关于asp导出excel的问题!

luyanpeng 2004-12-11 10:15:01
<!--#include file="../conn/HR_Conn.asp"-->
<%
'Set xlApp = Server.CreateObject("EXCEL.APPLICATION")
Set xlApp = CreateObject("EXCEL.APPLICATION")
xlApp.Visible = true
'response.Write(xlApp.Visible)
set rs=Server.CreateObject("ADODB.Recordset")
strSQL="select * from Salary"
rs.open strSQL,conn,3,3
'dim xl
Set xlBook = xlApp.Workbooks.Add
Set xlSheet1 = xlBook.Worksheets(1)
xlSheet1.cells(1,1).value ="职工工资一览表 "
xlSheet1.range("A1:W1").Font.Bold=true
xlSheet1.range("A1:W1").Font.Size=20
xlSheet1.range("A1:W1").merge
xlSheet1.cells(2,1).value = "姓名"
xlSheet1.cells(2,2).value = "性别"
xlSheet1.cells(2,3).value = "职工编号"
xlSheet1.cells(2,4).value = "一月"
xlSheet1.cells(2,5).value = "二月"
xlSheet1.cells(2,6).value = "三月"
xlSheet1.cells(2,7).value = "四月"
xlSheet1.cells(2,8).value = "五月"
xlSheet1.cells(2,9).value = "六月"
xlSheet1.cells(2,10).value = "七月"
xlSheet1.cells(2,11).value = "八月"
xlSheet1.cells(2,12).value = "九月"
xlSheet1.cells(2,13).value = "十月"
xlSheet1.cells(2,14).value = "十一月"
xlSheet1.cells(2,15).value = "十二月"
xlSheet1.cells(2,16).value = "其他"
xlSheet1.cells(2,17).value = "当年公基金"
xlSheet1.cells(2,17).ColumnWidth=10
xlSheet1.cells(2,18).value = "全部工资"
xlSheet1.cells(2,19).value = "发工资月数"
xlSheet1.cells(2,19).ColumnWidth=10
xlSheet1.cells(2,20).value = "平均工资"
xlSheet1.cells(2,21).value = "单位"
xlSheet1.cells(2,21).ColumnWidth=12
xlSheet1.cells(2,22).value = "职工类别"
xlSheet1.cells(2,23).value = "备注"
cnt = 3
do while not rs.eof
xlSheet1.cells(cnt,1).value = rs("Name")
xlSheet1.cells(cnt,2).value = rs("Sex")
xlSheet1.cells(cnt,3).value = rs("EmpId")
xlSheet1.cells(cnt,4).value = rs("Jan")
xlSheet1.cells(cnt,5).value = rs("Feb")
xlSheet1.cells(cnt,6).value = rs("Mar")
xlSheet1.cells(cnt,7).value = rs("Apr")
xlSheet1.cells(cnt,8).value = rs("May")
xlSheet1.cells(cnt,9).value = rs("Jun")
xlSheet1.cells(cnt,10).value = rs("Jul")
xlSheet1.cells(cnt,11).value = rs("Aug")
xlSheet1.cells(cnt,12).value = rs("Sep")
xlSheet1.cells(cnt,13).value = rs("Oct")
xlSheet1.cells(cnt,14).value = rs("Nov")
xlSheet1.cells(cnt,15).value = rs("Dece")
xlSheet1.cells(cnt,16).value = rs("Others")
xlSheet1.cells(cnt,17).value = rs("Accumu")
xlSheet1.cells(cnt,18).value = rs("FullPay")
xlSheet1.cells(cnt,19).value = rs("FactMonths")
xlSheet1.cells(cnt,20).value = rs("AvgPay")
xlSheet1.cells(cnt,21).value = rs("Department")
xlSheet1.cells(cnt,22).value = rs("EmpClass")
xlSheet1.cells(cnt,23).value = rs("Remark")
rs.movenext
cnt = cint(cnt) + 1
loop
xlSheet1.Application.Visible = true
'response.Write(xlSheet1.Application.Visible)
set xlApp=nothing
xlApp.close
set rs=nothing
rs.close
%>

不知道为什么,已经把xlApp.Visible = true,但是输出的时候总是False,请高手帮忙!
觉得总是连接的问题!
...全文
182 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kenvin05 2004-12-11
  • 打赏
  • 举报
回复

我一个很简单的方法,
用fso就可以了。。。
所有数据信息都先存在export()二维数组中

set fso=server.createobject("scripting.filesystemobject")
strExcelFile=server.MapPath("excel/export.xls")
if fso.fileExists(strExcelFile) then fso.deletefile strExcelFile
Set xslFile = fso.CreateTextFile(strExcelFile , True)
writestr="用户名" & vbTab & "文章数" & vbLf

for i=1 to numi
for j=1 to 2
writestr=writestr& export(i,j)& vbTab
next
writestr=writestr &vbLf
next

xslFile.WriteLine(writestr)
xslFile.Close
set fso=nothing


很简洁吧?哈哈哈哈哈
hhjjhjhj 2004-12-11
  • 打赏
  • 举报
回复
服务器端一概不能有可见窗口,要么出错,要么无效。
你要在服务器上xlApp.Visible = true干吗?
luyanpeng 2004-12-11
  • 打赏
  • 举报
回复
...............

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧