导出excel时报错,急!
用y7967给告诉我的代码加到页面上,报错,说缺少对像,我对那行做了说明。
<html>
<head>
<title>利用ADO分页</title>
</head>
<body>
<!-- METADATA TYPE="typelib" File="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
Dim cn,rs,sh_name
Dim iPage
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Driver={SQL Server};Server=cd;Database=ASPTest;" & _
"UID=sa;PWD=sa"
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.PageSize = 1 '这个值读者在使用时可根据需要设置
sh_name=trim(Request("sh_name"))
rs.Open "SELECT * FROM Chapter8 where 名称 like '%"&sh_name&"%'",cn,adOpenStatic,adLockReadOnly
If Len(Request("page")) = 0 Then
iPage = 1
Else
iPage = Request("page")
End If
rs.AbsolutePage = iPage
%>
<%sub btnExport_onclick()
dim objExcel
on error resume next
Set objExcel = CreateObject("excel.application")
With objExcel
.visible =true
.workbooks.add
.sheets("sheet1").select
End with
m_row="0"
for a=0 to document.all.mytable.rows.length-1
m_row = cstr(int (m_row)+1)
for b=0 to document.all.mytable.rows(a).cells.length-1
m_col = chr(asc("A")+b)
objexcel.range(m_col&m_row).select
M_value = document.all.mytable.rows(a).cells(b).innerText \\这里报缺少对像
objexcel.activecell.value=cstr(m_value)
next
next
objexcel.visible=true
objexcel.range("A1").select
End sub
%>
<p align="center">图书信息第<% =iPage%>页</p>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="646" align="center" id="mytable">
<form name="1">
<input name="sh_name" type="text"/>
<input type="submit" name="Button1" value="查 询" id="Button1" />
</form>
<tr>
<td width="33">编号</td>
<td width="98">名称</td>
<td width="37">作者</td>
<td width="56">类别</td>
<td width="135">出版社</td>
<td width="69">出版日期</td>
<td width="33">价格</td>
<td width="39">页数</td>
</tr>
</tr>
<%
For i =1 To rs.PageSize
If Not rs.Eof Then
%>
<tr>
<td width="33"><%=rs(0)%> </td>
<td width="98"><%=rs(1)%> </td>
<td width="37"><%=rs(2)%> </td>
<td width="56"><%=rs(3)%> </td>
<td width="135"><%=rs(4)%> </td>
<td width="69"><%=rs(5)%> </td>
<td width="33"><%=rs(6)%> </td>
<td width="39"><%=rs(7)%> </td>
</tr>
<%
End If
If Not rs.Eof Then rs.MoveNext
Next
%>
</table>
<p align="center">
<% If CInt(iPage) = 1 Then %>
第一页|上一页|
<% Else %>
<a href="08_07.asp?sh_name=<%=sh_name%>&page=1">第一页</a>|
<a href="08_07.asp?sh_name=<%=sh_name%>&page=<% = iPage - 1 %>">上一页</a>|
<% End If %>
<% If CInt(iPage) = CInt(rs.PageCount) Then %>
下一页| 最后一页
<% Else %>
<a href="08_07.asp?sh_name=<%=sh_name%>&page=<% = iPage + 1 %>">下一页</a>|
<a href="08_07.asp?sh_name=<%=sh_name%>&page=<% = rs.PageCount %>">最后一页</a>
<% End If %>
<%
Response.Write(rs.Pagecount)
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
%>
<td><input type=button name="out_excel" onClick="btnExport_onclick()" value="导出" class="notPrint"> </td>
</body>
</html>