CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  ASP

高分求asp+acess如何导出并下载exxel文件

楼主guolaizuozuo(guolaizuozuo)2005-04-01 11:40:01 在 Web 开发 / ASP 提问

高分求asp+acess如何导出并下载exxel文件,主要能导出和下载就可以了 问题点数:0、回复次数:1Top

1 楼arrowy(清云卷浪)回复于 2005-04-01 12:04:07 得分 0

导出页:  
  <%  
                    '   ------------------------------数据库连接--------------------------  
  dim   conn   ,rs  
                    set   conn   =   ...  
                    '   ------------------------------数据导出函数------------------------  
                      function   XXX()  
                              '写你要导出的  
                      end   function  
  '-------------------------------表头信息----------------------------  
  Dim   ObjFso,XlsPath,StrLine,StrLine02,ResponseStr  
  Set ObjFso   =   Server.CreateObject("Scripting.FileSystemObject")  
  Fname   =   ProjectName   &   "_表名_"   &   Date()   &   ".xls"  
  XlsPath   =   Server.MapPath(Fname)  
  StrLine=""  
  If     ObjFso.FileExists(XlsPath)     Then      
  ObjFso.DeleteFile(XlsPath)      
  End   If      
  '--创建EXCEL文件      
  Set   NewFile     =     ObjFso.CreateTextFile(XlsPath,true)    
       
  StrLine   =   "XX表"  
  NewFile.WriteLine   StrLine  
  StrLine   =   "名称:     "   &   ProjectName  
  NewFile.WriteLine   StrLine  
  StrLine   =   "信息I:     "   &   Pm  
  NewFile.WriteLine   StrLine  
  StrLine   =   "信息II:     "   &   Cm  
  NewFile.WriteLine   StrLine  
  StrLine   =   "信息III:   (万元)"  
  NewFile.WriteLine   StrLine  
  StrLine   =   "编     号"   &   chr(9)   &   "人员"   &   chr(9)   &   "字段名I"   &   chr(9)   &   "字段名II"   &   chr(9)   &   "字段名III"   &   chr(9)   &   "字段名IV"   &   chr(9)   &   chr(9)   &   "字段名V"  
  NewFile.WriteLine   StrLine  
  StrLine   =   "             "   &   chr(9)   &   "             "   &   chr(9)   &   "                 "   &   chr(9)   &   "                                 "   &   chr(9)   &   "             "   &   chr(9)   &   "字段名VI"   &   chr(9)   &   "字段名VII"     &   chr(9)   &   "           "  
  NewFile.WriteLine   StrLine  
   
  '   ================================  
                    '   这里写你的从ACCESS导出数据的函数(顺序什么的要按上面字段顺序)  
  '   ================================  
   
  conn.close  
  set   conn=nothing  
  Set   NewFile   =   Nothing  
  Set   ObjFso   =   Nothing  
  Response.Redirect("testDownLoad.asp?fp="   &   Fname)  
  %>  
   
   
  下载页   TestDownLoad.asp:  
  <%  
   
  '   ///////////////////////////////////////////////////////  
  '   下载操作  
  '  
  '   输入参数:  
  '   fp   ->   文件链接地址  
  '   ///////////////////////////////////////////////////////  
   
   
  Response.Buffer   =   true  
  Response.Clear  
   
    Dim   FilePath,url  
    Dim   fso,fl,flsize  
    Dim   Dname  
    Dim   objStream,ContentType,flName,isre,url1  
  '*********************************************调用时传入的下载文件名  
    Dname=Trim(request("fp"))  
  '******************************************************************  
    If   Dname<>""   Then  
  '******************************下载文件存放的服务端目录  
      url   =   Dname  
  '***************************************************  
    End   If  
   
    Set   fso=Server.CreateObject("Scripting.FileSystemObject")  
      Set   fl=fso.getfile(url)  
      flsize=fl.size  
      flName=fl.name  
      Set   fl=Nothing  
      Set   fso=Nothing  
   
      Set   objStream   =   Server.CreateObject("ADODB.Stream")  
      objStream.Open  
      objStream.Type   =   1  
      objStream.LoadFromFile   url  
   
   
        Select   Case   lcase(Right(flName,   4))  
          Case   ".asf"  
            ContentType   =   "video/x-ms-asf"  
          Case   ".avi"  
            ContentType   =   "video/avi"  
          Case   ".doc"  
            ContentType   =   "application/msword"  
          Case   ".zip"  
            ContentType   =   "application/zip"  
  Case   ".rar"  
    ContentType   =   "application/octet-stream"  
          Case   ".xls"  
            ContentType   =   "application/vnd.ms-excel"  
          Case   ".gif"  
            ContentType   =   "image/gif"  
          Case   ".jpg",   "jpeg"  
            ContentType   =   "image/jpeg"  
          Case   ".wav"  
            ContentType   =   "audio/wav"  
          Case   ".mp3"  
            ContentType   =   "audio/mpeg3"  
          Case   ".mpg",   "mpeg"  
            ContentType   =   "video/mpeg"  
          Case   ".rtf"  
            ContentType   =   "application/rtf"  
          Case   ".htm",   "html"  
            ContentType   =   "text/html"  
          Case   ".txt"  
            ContentType   =   "text/plain"  
  Case   ".mdb"  
    ContentType   =   "application/msaccess"  
          Case   Else  
            ContentType   =   "application/octet-stream"  
        End   Select  
   
     
   
        Response.AddHeader   "Content-Disposition",   "attachment;   filename="   &   flName  
        Response.AddHeader   "Content-Length",   flsize  
   
        Response.Charset   =   "UTF-8"  
        Response.ContentType   =   ContentType  
   
        Response.BinaryWrite   objStream.Read  
        Response.Flush  
        Response.Clear()  
      objStream.Close  
      Set   objStream   =   Nothing  
   
  %>  
   
  Top

相关问题

  • ASP导出EXCEL问题
  • 在asp中导出问题
  • ASP里面做Excel导出,急,100分
  • ASP导出EXCEL出现问题!
  • asp能不能实现导出到EXCEL?
  • asp excel 导出空格处理问题
  • 使用asp怎样将数据导出到excel文件
  • 将Excel用ASP导入及将数据导出为Excel详解
  • 求ASP中的数据导出EXCEl的代码
  • asp中(access数据库)向execl导出数据的问题?

关键词

  • 文件
  • 下载
  • application
  • asp
  • 导出
  • contenttype
  • flname
  • objstream
  • dname
  • fl

得分解答快速导航

  • 帖主:guolaizuozuo

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo