Methods of exporting data to excel in ASP

Source: Internet
Author: User

< % dim s,sql,filename,fs,myfile,x   Set fs = server.CreateObject( "scripting.filesystemobject" ) ‘--假设你想让生成的EXCEL文件做如下的存放 filename = Server.MapPath( "order.xls" ) ‘--如果原来的EXCEL文件存在的话删除它 if fs.FileExists(filename) then     fs.DeleteFile(filename) end  if ‘--创建EXCEL文件 set myfile = fs.CreateTextFile(filename,true)     StartTime = Request( "StartTime" ) EndTime = Request( "EndTime" ) StartEndTime = "AddTime between #" & StartTime & " 00:00:00# and #" & EndTime & " 23:59:59#" strSql = "select * from mksuers " Set rstData =conn.execute(strSql) if not rstData.EOF and not rstData.BOF then       dim  trLine,responsestr     strLine= ""     For each x in rstData.fields       strLine = strLine & x.name & chr(9)     Next   ‘--将表的列名先写入EXCEL     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 Response.Write  "生成EXCEL文件成功,点击<a href=" / " rel=" external nofollow " order.xls" " target=" "_blank" ">下载!" rstData.Close set rstData = nothing Conn.Close Set Conn = nothing %>

As can be seen, this method is everywhere is the text file, but the suffix name changed to XLS.

And then it looks like it's Excel.

Compared with this method, the efficiency is high.

It is recommended that you use this method of writing files for Excel operations.

Methods of exporting data to excel in ASP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.