关于asp对excel的操作,在线等,进者有分!

zjwhwly 2005-09-13 03:06:49
运行时,错误信息如下
错误 '80010105'
服务器出现意外情况。

/city/lh_b.asp,行105
在这个文件中,我先上传文件,然后上传后的excel进行操作,通过读excel表的一列数据,把它插入到SQL表的相应字段中,第一次执行正常,第二次执行就提示上面所说的错误信息。后来我用excel打开上传后的excel文件,竟然提示该文件正处于锁定状态,xx正在编辑,我想问题就是在这里了,而且错误信息中所说的行105的语句是Set xlbook = xlApp.Workbooks.Open(strsource),也就是说打不开excel文件,但是我不知道该怎么修改
<%

FilePath="excel"
FileMaxSize=100000
FileType=".xls"
fileweb="/"
nameset =1
pathset =0
''将当前的日期和时间转为文件名
function makefilename(fname)
fname = now()
fname = replace(fname,"-","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
makefilename=fname
end function

dim upload,file,formName,iCount,team3
set upload=new upload_5xSoft ''建立上传对象
if Pathset > 0 then ''得到上传目录
UpFilePath = upload.form("pic")
else
UpFilePath = FilePath
''在目录后加(/)
if right(UpFilePath,1)<>"/" then UpFilePath=UpFilePath&"/"
end if

team3=upload.form("team3")
picsm=upload.form("pic")
iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
if file.FileSize<FileMaxSize then ''如果未超过文件大小限制

if FileType<>"" then '如果限制了上传文件类型
if Instr(FileType,GetExtendName(file.FileName)) then
TypeFlag = 1 '文件为允许的类型
else
TypeFlag = 0 '文件为不允许的类型
response.write "<script>alert('不支持您所上传的文件类型:"& GetExtendName(file.FileName) &"')</script>"
response.write "<script>history.back(-1)</script>"
response.end
end if
else
TypeFlag = 1 '没有限制上传文件类型

end if

if TypeFlag = 1 then
newfilename = year(now())& month(now())& day(now())&hour(now())&minute(now())&second(now()) '新文件名
vfname = newfilename
if nameset = 1 then
fname = vfname&"." & GetExtendName(file.FileName)
elseif nameset =2 then
fname = file.FileName
elseif nameset = 3 then
fname = vfname & file.FileName
end if
file.SaveAs Server.mappath(UpFilePath&fname) ''保存文件
'response.write file.FilePath&file.FileName&" ("&file.FileSize&") => 上传图片成功! <br>"
iCount=iCount+1
' fileStr = fileStr & "<img src='pic/addon.gif'><a href='"& UpFilePath&file.FileName&"' target='_blank'>查看上传的文件:<font color='red'>" & file.FileName &"</font> ("& file.FileSize &" kb)</a><br>"
FileNameStr = UpFilePath&fname

end if

else
response.write "<script>alert('文件大小超出限制,您最多可以上传 "& FileMaxSize &"个字节的文件数据')</script>"
response.write "<script>history.back(-1)</script>"
response.end
exit for
end if
end if
set file=nothing
next

set upload=nothing ''删除此对象


sub HtmEnd(Msg)
set upload=nothing
end sub


function GetExtendName(FileName)
dim ExtName
ExtName = LCase(FileName)
ExtName = right(ExtName,3)
ExtName = right(ExtName,3-Instr(ExtName,"."))
GetExtendName = ExtName
end function
%>
<% dim city_code
city_code=session("city")
Set xlApp = server.CreateObject("Excel.Application")
strsource =Server.mappath(UpFilePath&fname)
Set xlbook = xlApp.Workbooks.Open(strsource)
Set xlsheet = xlbook.Worksheets(1)
i=2
dim s
do while xlsheet.cells(i,1)<>""
s=xlsheet.cells(i,1)
i=i+1
if team3="" then
sql="insert into mobile_list(mobile,city_code) values('"&s&"'',"&city_code&"')"
else
sql="insert into mobile_list(mobile,city_code,team_id) values('"&s&"',"&city_code&"','"&team3&"')"
end if
conn.execute(sql)
loop
set xlsheet=nothing
set xlbook=nothing
xlApp.Quit
Set xlApp=Nothing
conn.close
set conn=nothing
response.write ("<script>alert(""号码分配成功!"");this.location.href='lh.asp';</script>")
%>


...全文
177 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanglemail 2005-09-19
  • 打赏
  • 举报
回复
学习学习 顶
jamila8 2005-09-13
  • 打赏
  • 举报
回复
这么复杂,顶一下
ziyantan 2005-09-13
  • 打赏
  • 举报
回复
百度关键字:Access to Excel 子言
rainxiang 2005-09-13
  • 打赏
  • 举报
回复
<%
ASP读取EXCEL注事项
i)将Excel97或Excel2000生成的XLS文件(book)看成一个数据库,其中的每一个工作表(sheet)看成数据库表
ii)ADO假设Excel中的第一行为字段名.所以你定义的范围中必须要包括第一行的内容
iii)Excel中的行标题(即字段名)不能够包含数字. Excel的驱动在遇到这种问题时就会出错的。例如你的行标题名为“F1”
iiii)如果你的Excel电子表格中某一列同时包含了文本和数字的话,那么Excel的ODBC驱动将不能够正常, 处理这一行的数据类型,你必须要保证该列的数据类型一致

WIN2000SERVER+IIS5 测式通过



Dim Conn,Driver,DBPath,Rs

' 建立Connection对象

Set Conn = Server.CreateObject("ADODB.Connection")

Driver = "Driver={Microsoft Excel Driver (*.xls)};"

DBPath = "DBQ=" & Server.MapPath( "test.xls" )

'调用Open 方法打开数据库

Conn.Open Driver & DBPath

'DSN连接方式

'Conn.Open "Dsn=test"

'注意 表名一定要以下边这种格试 "[表名$]" 书写

Sql="Select * From [Sheet1$] where 序号=0"

Set Rs=Conn.Execute(Sql)

IF Rs.Eof And Rs.Bof Then

Response.write "没有找到您需要的数据!!"

Else

Do While Not Rs.EOF

Response.write Rs("姓名")

Rs.MoveNext

Loop

End IF

Rs.Close

Set Rs=nothing

Conn.Close

Set Conn=Nothing

'Response.Write "成功!"

%>

tigerwen01 2005-09-13
  • 打赏
  • 举报
回复
应该是权限问题,运行dcomcnfg设置权限。

28,406

社区成员

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

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