在ASP中,不用ODBC,如何直接调用Excel数据?
在调用处理处,究竟是使用:
xlApp.quit
还是使用:
set xlApp=nothing
是这个程序成败的关键,如果使用不当,嘿嘿,每运行一次程序,就在你的机器里就增加一个无法释放的excel进程(!)
具体程序代码见下:
<%@language=vbscript %>
<%
Set xlApp = server.CreateObject("Excel.Application")
strsource = "c:\excel\stock1.xls"
' 数据库位置
Set xlstock = xlApp.Workstocks.Open(strsource)
Set xlsheet = xlstock.Worksheets(1)
i=1
response.write "<table cellpadding=0 cellspacing=0 border=1 width=500>"
while xlsheet.cells(i,1)<>""
response.write "<tr>"
response.write " <td height=20 align=center width=100>" & xlsheet.Cells(i, 1) & "</td>"
response.write " <td height=20 align=center width=200>" & xlsheet.Cells(i, 2) & "</td>"
response.write " <td height=20 align=center width=200>" & xlsheet.Cells(i, 3) & "</td>"
response.write "</tr>"
i=i+1
wend
response.write "</table>"
set xlsheet=nothing
set xlstock=nothing
xlApp.quit
%>
Excel表stock1.xsl的结构如下(注意,Excel 起始行是1而不是0):
序 号(不能为空)
姓 名
股 票
1
孙春亮
6000
2
宋颜浩
5000
3
费文华
5600
asp调用Excel数据
原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]
相关文章:
- 同一个用户不允许同时登陆两次(2007-11-15 1:17:43)
- 罗列全部session和application(2007-11-12 6:26:16)
- 访问和更新Cookies集合(2007-11-11 1:42:29)
- asp中cookie使用示例(2007-11-7 3:2:28)
- asp重定向-response.redirect和server.transfer(2007-10-24 9:18:30)
- vbscript Replace 函数(2007-10-21 4:33:2)
- asp:Server对象(2007-10-11 7:9:58)
- vbscript:日期格式常数(2007-10-10 7:30:49)
- ASP动态包含文件的改进方法(2007-10-8 1:5:48)
- For...Next 语句(2007-10-4 9:43:2)
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
