文章分类 Classification
asp导出excel电子表格
稿件来源: 阳光企业网站管理系统 撰稿作者: 太阳光 发表日期: 2011-10-15 阅读次数: 316 查看权限: 游客查看
这是截取我制作项目中的一个小例子
<!--#include file="inc/Scs_conn.asp"--> <% '================================== '=功 能:主调代码,相应功能皆有说明 '=文 件:导出excel '================================== Response.Clear Dim objFSO,xlsFile,objStream Dim FileName Dim XlsSize,XlsName Set objFSO = Server.CreateObject("Scripting.FileSystemObject") FileName = Server.MapPath(".") & "\" & Replace(objFSO.GetTempName,".tmp","") & ".xls" If objFSO.FileExists(FileName) Then objFSO.DeleteFile(FileName) End If Set xlsFile = objFSO.CreateTextFile(FileName,true) XlsName="人员总表" '保存的文件名 xlsFile.WriteLine "工号"& CHR(9) &"姓名"& CHR(9) &"性别"& CHR(9) &"职务"& CHR(9) &"职称"& CHR(9) &"单位" Sql="Select * From [user] Where title_cat<>-1 and "&i_Id&"='"&s_Title&"' order by units" Set Rs=Server.Createobject("adodb.recordset") Rs.open Sql,Conn,1,1 Do While Not Rs.Eof xlsFile.WriteLine CHR(39)&Rs("id")& CHR(9) &Rs("user_name")& CHR(9) &Rs("sex")& CHR(9) &Rs("user_duty")& CHR(9) &Rs("title")& CHR(9) &Rs("units") Rs.MoveNext Loop Rs.Close:Set Rs=Nothing CloseDatabase '关闭数据库 Set xlsFile = Nothing Set xlsFile = objFSO.GetFile(FileName) XlsSize = xlsFile.Size Set xlsFile = Nothing Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open objStream.Type = 1 objStream.LoadFromFile FileName Response.AddHeader "Content-Disposition", "attachment; filename="&Server.URLEncode(XlsName)&".xls" Response.AddHeader "Content-Length", XlsSize Response.Charset = "UTF-8" Response.ContentType = "application/vnd.ms-excel" Response.BinaryWrite objStream.Read Response.Flush Response.Clear() objStream.Close Set objStream = Nothing objFSO.DeleteFile FileName Set objFSO = Nothing %>
关键词: asp导出excel,电子表格,导出excel 编辑时间: 2012-06-07
0
高兴0
支持0
搞笑0
不解0
谎言0
枪稿0
震惊0
无奈0
无聊0
反对0
愤怒
0%(0)
0%(0)
- 中搜索:asp导出excel电子表格
- 中搜索:asp导出excel电子表格
- 暂无评论
文章图片 article Pictrue
网友评论