ndfweb.cn

asp生成excel的代码


2010-01-01 08:55:46 (5844)


<%@ LANGUAGE="VBSCRIPT" %>
<%
If Response.IsClientConnected Then 
Response.Flush 
Else 
Response.End
End If
dim conn
dim connstr
dim db
set conn = server.createobject("ADODB.CONNECTION")
db="data/wyxh.asp"
on error resume next
connstr = "Driver={MicroSoft Access Driver (*.mdb)};DBQ="& Server.MapPath(""&db&"") &";

UID=; PWD=;"
'response.write connstr

conn.open connstr
%>
<%
dim oRs,sql
set oRs=Server.CreateObject("ADODB.Recordset")
sql = "select * from User order by id desc"
oRs.open sql,conn,1,1
%>
<%
Response.ContentType = "application/msexcel"
Dim xlWorkSheet
Dim xlApplication
Set xlApplication = Server.CreateObject("Excel.Application")
xlApplication.Visible = False
xlApplication.Workbooks.Add
Set xlWorksheet = xlApplication.Worksheets(1)
xlWorksheet.Cells(1,1).Value = "编号"
xlWorksheet.Cells(1,2).Value = "姓名"
xlWorksheet.Cells(1,3).Value = "地址"
xlWorksheet.Cells(1,4).Value = "班级"
xlWorksheet.Cells(1,5).Value = "IP"
xlWorksheet.Cells(1,6).Value = "金额"
xlWorksheet.Cells(1,7).Value = "email"
xlWorksheet.Cells(1,8).Value = "QQ"
xlWorksheet.Cells(1,9).Value = "性别"
xlWorksheet.Cells(1,1).Interior.ColorIndex = 16
xlWorksheet.Cells(1,2).Interior.ColorIndex = 16
xlWorksheet.Cells(1,3).Interior.ColorIndex = 16
xlWorksheet.Cells(1,4).Interior.ColorIndex = 16
xlWorksheet.Cells(1,5).Interior.ColorIndex = 16
xlWorksheet.Cells(1,6).Interior.ColorIndex = 16
xlWorksheet.Cells(1,7).Interior.ColorIndex = 16
xlWorksheet.Cells(1,8).Interior.ColorIndex = 16
xlWorksheet.Cells(1,9).Interior.ColorIndex = 16
iRow = 2
If Not oRS.EOF Then
Do Until oRS.EOF
xlWorksheet.Cells(iRow,1).Value = oRS("No")
xlWorksheet.Cells(iRow,2).Value = oRS("name")
xlWorksheet.Cells(iRow,3).Value = oRS("address") '这里是adress还是address?你自己好好看看数据库
xlWorksheet.Cells(iRow,4).Value = oRS("class")
xlWorksheet.Cells(iRow,5).Value = oRS("ip")
xlWorksheet.Cells(iRow,6).Value = oRS("money")
xlWorksheet.Cells(iRow,7).Value = oRS("email")
xlWorksheet.Cells(iRow,8).Value = oRS("QQ")
xlWorksheet.Cells(iRow,9).Value = oRS("sex")
iRow = iRow + 1
oRS.MoveNext
Loop
End If
rannum=int(1000*rnd)
YoureIp=trim(Request.ServerVariables("REMOTE_ADDR"))
YoureIp=left(YoureIp,len(YoureIp)-4)
YoureIp=replace(YoureIp,".","")
rndfile=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)

&rannum&YoureIp
strFile = rndfile
xlWorksheet.SaveAs Server.MapPath(strFile & ".xls")
xlApplication.Quit
'Close the Workbook
Set xlWorksheet = Nothing
Set xlApplication = Nothing
Response.Write("Click <a href=" & strFile & ".xls>Here</a> get XLS file")
%> 了解更多请访问:http://www.ndfweb.cn/news-492.html
  NDF俱乐部
  国际域名注册
  建站咨询
合作伙伴:万网 | 新网 | 新网互联 NDF网站建设淘宝店 | 实用工具 | 外貿網站建設 | 联系我们
鲁公网安备 37110202000336号 鲁ICP备2021027697号-1 Sitemap - RSSRSS订阅