急!!asp操作excel问题,各位高手一定要帮忙看看,在线等候!
我想把数据库内容插入到已存在的excel表格中,但是一直提示错误(“/iisHelp/common/500-100.asp,行242 错误 '80010105',服务器出现意外情况,行33 ”),估计就是创建excel对象实例那一块的问题,源代码如下:
<!--#include file="conn.asp" -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
'on error resume next
'定义日期文件名
function filename()
dim year1,month1,day1,hour1,minute1,second1
year1 = year(now())
month1 = month(now())
if len(month1) < 2 then month1 = "0"&month1
day1 = day(now())
if len(day1) < 2 then day1 = "0"&day1
hour1 = hour(now())
if len(hour1) < 2 then hour1 = "0"&hour1
minute1 = minute(now())
if len(minute1) < 2 then minute1 = "0"&minute1
second1 = second(now())
if len(second1) < 2 then second1 = "0"&second1
filename = year1&month1&day1&hour1&minute1&second1
end function
'excel文件名
excelFileName = filename&".xls"
'对sheet1进行操作
sub CreateExcelRecordset(eFileName,eSheet)
set rs = server.CreateObject("adodb.recordset")
sql = "select * from member order by memb_id asc"
rs.open sql,conn,1,3
set xlApplication = CreateObject("Excel.Application")
xlApplication.WorkBooks.Open(eFileName)
Set xlWorksheet = xlApplication.Worksheets(eSheet)
iRow = 2
If Not rs.EOF Then
Do Until rs.EOF
For i = 0 To rs.fields.Count-1
xlWorksheet.Cells(iRow,i + 1).Value = rs.fields(i)
Next
iRow = iRow + 1
rs.MoveNext
Loop
End If
Set xlWorksheet = Nothing
xlApplication.Quit
Set xlApplication = Nothing
rs.close
set rs = nothing
End sub
path = server.MapPath(".")
path1 = path&"\mod\newdot.xls"
set fso = server.CreateObject("scripting.filesystemobject")
fso.copyfile path1,path&"\"
fso.movefile path&"\newdot.xls",path&"\"&filename&".xls"
set fso = nothing
CreateExcelRecordset path&"\"&excelFileName,1
response.write "ok"
%>