这次做的活是asp操作excel,全程序是每行都标出,然后像填空一样做的。现在被我改成了动态显示每行的项,再逐行显示,最后做一个汇总。
1、FSO找到excel文件
<%
Dim fso,folder,file
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(Server.MapPath("data"))
Dim name
For Each file in folder.Files
name = fso.GetBaseName(file)
%>
<li><%=name%></li>
<%
Next
%>
2、连接excel文件,获取第一个sheet的name
<%
//建立Connection对象
Set Conn_qc = Server.CreateObject("ADODB.Connection")
Driver = "Provider=Microsoft.Jet.OLEDB.4.0;"
DBParm = "Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
//调用Open 方法打开数据库
DBPath = "Data Source=" & Server.MapPath("data\" & table & ".xls") & ";" '注意:此处的table变量为文件名,可由上一个方法得到
Conn_qc.Open Driver & DBPath & DBParm
//获取第一个sheet的名称
Set rs=Conn_qc.OpenSchema(20)
TableName = rs("Table_name")
rs.Close
//查询数据
Sql="Select * From [" & TableName & "]"
//response.write(sql)
'Set Rs=Conn.Execute(Sql)
rs.open sql, Conn_qc, 1, 1 '此处可以解决recordcount为 -1 的问题
if rs.recordcount<>0 then
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
<tr>
<%for i=0 to rs.fields.count-1%>
<td align="center" valign="middle" bgcolor="#F2F8FF" ><% =rs(i).Name %></td>
<%next%>
</tr>
<tr>
<%for i=0 to rs.fields.count-1%>
<td align="center" valign="middle" class="f"><%=rs(i)%></td>
<%next%>
</tr>
</table>
<%
end if
rs.close
set rs=nothing
Conn_qc.close
%>