asp导出excel文件格式

asp页面从数据库中查询出一些数据,要将这些数据导出为Excel文件的格式

强烈推荐:https://www.cnblogs.com/yufume/p/6718332.html

注意:这个方法导出的excel表格在当前asp文件所在的目录下

Set ors = Server.CreateObject("ADODB.RecordSet")
ors.Open v_sql,oconn,3,1
dim s,filename,fs,myfile,x
set fs = server.CreateObject("scripting.filesystemobject")
filename = server.MapPath("exp.xls")
if fs.FileExists(filename) then 
    fs.DeleteFile(filename)
end if
set myfile = fs.CreateTextFile(filename,true)
StartTime = Request("StartTime") 
EndTime = Request("EndTime") 
StartEndTime = "AddTime between #"& StartTime &" 00:00:00# and #"& EndTime &" 23:59:59#" 
set rstData = oconn.execute(v_sql)
if not rstData.eof and not rstData.bof then 
    strLine = ""
    strLine = "信息标题" & chr(9) & "所在栏目" & chr(9) & "作者" & chr(9) & "报送单位" & chr(9) &"发布日期" & chr(9)
    myfile.writeline strLine
    do while not rstData.eof
        strLine = ""
        for each x in rstData.fields
        strLine = strLine & x.value & chr(9)
        next
        myfile.writeline strLine
    rstData.MoveNext
    loop
end if

另外:如果遇到只要求导出查询结果的某几个字段,可以使用ratData(i).value

  strLine = strLine & rstData(1).value & chr(9) & rstData(10).value & chr(9) & rstData(14).value & chr(9) 
  myfile.writeline.strLine  //接着写入文件

展开阅读全文

没有更多推荐了,返回首页