当前位置:编程学习 > C#/ASP.NET >>

直接读取excel的问题,急!!

下面是我的asp代码,提示出错,在创建CreateObject("Excel.Application")前,是否要加载什么对象?
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>直接访问Excel</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style></head>

<body>
<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>

</body>
</html>
--------------------编程问答-------------------- using Excel = Microsoft.Office.Interop.Excel;

添加 Excel的引用试试 --------------------编程问答-------------------- 你的连接字符串是怎么写的?

没有看见 --------------------编程问答-------------------- 例如:


'第一种连接方式:
set conn=Server.CreateObject("ADODB.Connection")
Driver = "Driver={Microsoft Excel Driver (*.xls)};"
DBPath = "DBQ="&server.MapPath("test.xlsx")
conn.open Driver&DBPath

'第二种连接方式
'Set conn = Server.CreateObject("ADODB.Connection")  
'connStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("test.xls")&";Extended Properties='Excel 8.0;HDR=No;IMEX=1';"

'其中,hdr取值yes,no ,表示第一行是否为字段名
'imex   取值1,2,
'其中1   正是解决此问题的关键(也有人说取值1,只能在连续16行中出现上诉问题才能解决,未经证实?)
' 其中2   只查到有人用,但是不清楚具体代表什么! 

'HDR=Yes这个我说一下,这代表第一行是标题,不做为数据使用 ,如果用HDR=NO,则表示第一行不是标题,做为数据来使用。系统默认的是YES.

以上是在office2003下可以用 --------------------编程问答-------------------- 我没有创建连接哦,我这段代码是在客户端使用,就是说读取的excel文件在任意一台客户机都可以!!
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,