请高手帮写个asp生成excel的代码
答案:3 悬赏:30 手机版
解决时间 2021-03-25 16:27
- 提问者网友:山高云阔
- 2021-03-24 17:38
请高手帮写个asp生成excel的代码
最佳答案
- 五星知识达人网友:雾月
- 2021-03-24 19:06
我写了一个,把所有的数据都导出来了.本来想让你自己研究研究,可是,想想,还是算了.
<%@ 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 Here get XLS file")
%>
<%@ 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 Here get XLS file")
%>
全部回答
- 1楼网友:不甚了了
- 2021-03-24 21:45
高手。
- 2楼网友:怙棘
- 2021-03-24 20:10
semaly不错
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯