1。ASP对Excel的基本操作
1)建立Excel对象
Set objExcelApp=CreateObject(Excel.Application)
objExcelApp.DisplayAlerts=false'不显示警告
objExcelApp.Application.Visible=false‘不显示界面
2)读取已有的Excel文件
strAddr=Server.MapPath(".")
objExcelApp.WorkBooks.Open(strAddr & "TempletTable.xls")
Set objExcelBook=objExcelApp.ActiveWorkBook
Set objExcelSheets=objExcelBook.Worksheets
Set objExcelSheet=objExcelBook.Sheets(1)
2读取Excel文件实例
Exce表bookl.xsl,表的结构如下:
1 序号 名称 金额
2 1 张三 100
3 2 李四 200
4 3 王五 300
程序如下:
<%
Set xlApp=server.CreateObject("Excel.Application")
strsourc="c:\bookl.xls"
Set xlbook=xlApp.Workbooks.open(strsourc)
set xlsheet=xlbook.Worksheets(1)
i=1
response.write"<table cellpadding=0 ellspacing=0 border=1 width=250>"
while slsheer.cells(i,1)<>""
response.write"<tr>"
response.write" <td height=20 align=center width=50>" & xlsheet.Cells(i,1) & "</td>"
response.write" <td height=20 align=center width=50>" & xlsheet.Cells(i,2) & "</td>"
response.write" <td height=20 align=center width=50>" & xlsheet.Cells(i,3) & "</td>"
response.write "</tr>"
i=i+1
wend
response.write"</table>"
set xlsheet=nothing
set xlbook=nothing
xlApp.quit ’一定要加这一句set xlApp=nothing无法释放空间
%>