访问EXCEL为什么不成功呢?

oyh484203 2006-12-07 10:12:07
我在一本书上看到了一个关于直接访问EXCEL的实例
代码是这样的:
<form action="" method="post" name="form1">
<table width="400" height="276" border="0" align="center" background="add_manager.gif">
<tr>
<td width="123" height="83"> </td>
<td width="267" height="83"> </td>
</tr>
<tr>
<td height="42" align="right">请填写显示的列数:</td>
<td width="267" height="42"><input type="text" name="cln"></td>
</tr>
<tr>
<td align="right">Excel路径:</td>
<td><input name="asf" type="file" id="asf"></td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="Submit" value="查看" onClick="sd()"></td>
</tr>
</table>
</form>
<script language="vbscript">
sub sd()
set xlap=CreateObject("Excel.Application")
strsource=document.all.form1.asf.value
cln=document.all.form1.cln.value
set xlbook=xlap.Workbooks.open(strsource)
set xlsheet=xlbook.worksheets(1)
i=1
document.Write("<table border='0' align='center' cellspacing='1' bgcolor='#000000' width='400'>")
while xlsheet.cells(i,1)<>""
document.Write("<tr bgcolor='#FFFFFF'>")
for j=1 to cln
document.Write("<td>"&xlsheet.cells(i,j)&"</td>")
next
document.Write("</tr>")
i=i+1
wend
document.Write("</table>")
set xlsheet=nothing
set xlbook=nothing
xlap.quit
end sub
</script>
代码应该没问题,因为这本书是比较好的一本书
但是我运行时,当输好信息后总是提示:
错误:ActiveX部件 不能创建对象:Excel.Application
难道还要装什么组件才能运行,遇到过这种问题的前辈请指点迷津啊,
在线等~~多谢指点。。。。
...全文
153 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyh484203 2006-12-07
  • 打赏
  • 举报
回复
楼上的朋友谢谢你的回复,你所说的方法我知道,但是我说的方法怎么无法实现呢?
billflash 2006-12-07
  • 打赏
  • 举报
回复
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Dim con
con = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath( "test10.xls")&";Extended Properties=Excel 8.0;"

dim rs
set rs=server.CreateObject("adodb.recordset")
sql="select * from [销售报表$]"
rs.open sql,con,1,1
%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<table width="75%" border="1">
<tr>
<%
'rs.movenext
for s=0 to rs.Fields.count-1
%> <td><%=(rs(s).name)%></td>
<%
next
%>
</tr>
<% for i=1 to rs.recordcount%>
<tr>
<% for s=0 to rs.fields.count-1%>
<td><%=rs(rs(s).name)%></td>
<%next%>
</tr>
<%rs.movenext
next%>
</table>

</body>
</html>
oyh484203 2006-12-07
  • 打赏
  • 举报
回复
当点击“查看”按钮时显示如上的JS脚本错误。

28,391

社区成员

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

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