导出excel时报错,急!

liuchenghy 2006-02-23 11:10:14
用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>
...全文
120 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
response.appendheader("Content-Dispotion","attachment:filename=FileName.xls")
response.contentype="application/ms-execl"

把这个加在页面顶端,然后其余的直接和页面显示一样
wanghui0380 2006-02-24
  • 打赏
  • 举报
回复
呵呵,客户端的代码,你放到服务器端了,自然是错的
feng2112 2006-02-24
  • 打赏
  • 举报
回复
贴个别人的例子
<script language="javascript">
function saveas(Id)
{
var mStr;
mStr = window.document.body.innerHTML ;
var mWindow = window;
window.document.body.innerHTML =Id.innerHTML;
//mWindow.print();
document.write(window.document.body.innerHTML);
document.execCommand("saveAs","1","报表.xls");
window.document.body.innerHTML = mStr;
history.back();
}
</script>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<!--''''''''''''''''''''''''''''''''''''''''''-->
<div id="AreaPrint">

<!--''''''''''''''''''''''''''''''''''''''''''''-->

<table border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
<tr class="solidborder">
<td bgcolor="#ffffff">序号</td>
<td bgcolor="#ffffff">品名</td>
<td bgcolor="#ffffff">件数</td>
<td bgcolor="#ffffff">重量</td>
<td bgcolor="#ffffff">体积</td>
<td align="center" bgcolor="#eeeeee">应收合计</td>
<td align="center" bgcolor="#ffffff">应付合计</td>
<td align="center" bgcolor="#ffffff">毛利</td>
<td align="center" bgcolor="#ffffff">毛利率</td>
</tr>
<tr bgcolor="#eeeeee" class="solidborder">
<td colspan="11" align=right>总计:实际体积(0),实际重量(0),实际件数(0)
</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0%</td>
</tr>
</table>
<!--''''''''''''''''''''''''''''''''''''''''''-->
</div>
<!--''''''''''''''''''''''''''''''''''''''''''-->
<div class="noprint">
<table width="100%" align=center cellspacing="1">
<tr>
<td></td>
<td><div align="right">
<!--''''''''''''''''''''''''''''''''''''''''''-->
<a href="#" onclick="return saveas(AreaPrint)">生成EXCEL表</a>
<!--''''''''''''''''''''''''''''''''''''''''''-->
 <a href="javascript:self.print()" class="mhTextEmph">| 打印此页</a></div></td>
</tr>
zhanghongwen 2006-02-24
  • 打赏
  • 举报
回复
UP
liuchenghy 2006-02-24
  • 打赏
  • 举报
回复
怎么没人回呀,郁闷
liuchenghy 2006-02-24
  • 打赏
  • 举报
回复
我试试

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧