asp读取excel表数据
<%'以下实例中excel文件名为:list.xls,工作表名为:sheet1DimconnDimStrConnDimrsDimSqlSetconn=Server.Cre...
<% '以下实例中excel文件名为:list.xls,工作表名为:sheet1
Dim conn
Dim StrConn
Dim rs
Dim Sql
Set conn=Server.CreateObject("ADODB.Connection")
StrConn="Driver={Microsoft Excel Driver (*.xls)};DBQ="& Server.MapPath("list.xls")
conn.Open StrConn
Set rs = Server.CreateObject("ADODB.Recordset")
Sql="select * from [Sheet1$]"
rs.Open Sql,conn,2,2
%>
<center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<%
for i=0 to rs.Fields.Count-1
%>
<td width="1" bgcolor="#CCCCCC"></td>
<td height="28" bgcolor="#0099FF"><div align="center"><%=rs(i).Name%></div></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<%
do while Not rs.EOF
%>
<tr>
<%
for i=0 to rs.Fields.Count-1
%>
<td width="1" bgcolor="#CCCCCC"></td>
<td height="28" valign="bottom"><%=rs(i)%></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<tr>
<% '生成高度为1的空行(横线)
for i=0 to rs.Fields.Count-1
%>
<td height="1" bgcolor="#CCCCCC"></td>
<td height="1" bgcolor="#CCCCCC"></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<%
rs.MoveNext
Loop
rs.close
set rs=nothing
Conn.close
set StrConn=nothing
%>
</table>
</center>
这段代码,为什么首次运行不会出错,刷新就会出错,高手指点!! 展开
Dim conn
Dim StrConn
Dim rs
Dim Sql
Set conn=Server.CreateObject("ADODB.Connection")
StrConn="Driver={Microsoft Excel Driver (*.xls)};DBQ="& Server.MapPath("list.xls")
conn.Open StrConn
Set rs = Server.CreateObject("ADODB.Recordset")
Sql="select * from [Sheet1$]"
rs.Open Sql,conn,2,2
%>
<center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<%
for i=0 to rs.Fields.Count-1
%>
<td width="1" bgcolor="#CCCCCC"></td>
<td height="28" bgcolor="#0099FF"><div align="center"><%=rs(i).Name%></div></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<%
do while Not rs.EOF
%>
<tr>
<%
for i=0 to rs.Fields.Count-1
%>
<td width="1" bgcolor="#CCCCCC"></td>
<td height="28" valign="bottom"><%=rs(i)%></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<tr>
<% '生成高度为1的空行(横线)
for i=0 to rs.Fields.Count-1
%>
<td height="1" bgcolor="#CCCCCC"></td>
<td height="1" bgcolor="#CCCCCC"></td>
<%
next
%>
<td width="1" bgcolor="#CCCCCC"></td>
</tr>
<%
rs.MoveNext
Loop
rs.close
set rs=nothing
Conn.close
set StrConn=nothing
%>
</table>
</center>
这段代码,为什么首次运行不会出错,刷新就会出错,高手指点!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询