把table导出为EXCEL的问题

yaoshanghuan 2009-11-07 05:10:33
RT

使用 Response.ContentType = "application/vnd.ms-excel" 通过客户端安装的excel把网页中的内容导出为EXCEL。。现在可以导出为excel,但是有些问题,我要导出成excel的table是用从数据库中取出的值得到的table ,每次导出之前会从前一个页面发送两个日期到导出页面,然后根据两个日期来取得数据库中对应的两个日期之间的数据组成table,然后导出为EXCEL,,,,从查询分析器中运行根据日期变量组成的sql语句可以正确的得出要用的数据,但是在导出excel的时候却总是把数据库中的所有数据都导出了,,请大家帮忙看看原因,谢谢!

代码如下:

*************************************
<%
kaishi=trim(request("kaishi"))
jieshu=trim(request("jieshu"))
sql="select * from dinggou where (1=1)"
if kaishi<>"" and jieshu<>"" then
sql=sql&" and (subtime between '"&kaishi&" 00:00:00' and '"&jieshu&" 23:59:59')"
end if
sql=sql&" order by id asc"
'response.write(sql)
'response.End()
set rs=conn.execute(sql)
%>

<%
response.Clear()
Response.ContentType = "application/vnd.ms-excel"

%>
<table width="114%" border="0">
<tr>
<td colspan="10" align="center">订 单 下载</td>
</tr>
<tr>
<td width="12%" align="center">日期</td>
<td width="9%" align="center">客户姓名</td>
<td width="10%" align="center">性别</td>
<td width="11%" align="center">订购数量</td>
<td width="11%" align="center">固定电话</td>
<td width="7%" align="center">手机</td>
<td width="9%" align="center">收货地址</td>
<td width="8%" align="center">邮编</td>
<td width="10%" align="center">发货方式</td>
<td width="13%" align="center">其他要求</td>
</tr>
<%
do while not rs.eof
%>
<tr>
<td width="12%" align="center"><%=rs("subtime")%></td>
<td width="9%" align="center"><%=rs("username")%></td>
<td width="10%" align="center"><% if clng(rs("usersex"))=0 then%>男<%else%>女<%end if%></td>
<td width="11%" align="center"><%=rs("shuliang")%></td>
<td width="11%" align="center"><%=rs("phone")%></td>
<td width="7%" align="center"><%=rs("mobile")%></td>
<td width="9%" align="center"><%=rs("address")%></td>
<td width="8%" align="center"><%=rs("postcode")%></td>
<td width="10%" align="center"><%=rs("fahuo")%></td>
<td width="13%" align="center"><%=rs("message")%></td>
</tr>
<%
rs.movenext
loop

rs.close
set rs=nothing
%>
</table>
*************************************************************
...全文
98 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaoshanghuan 2009-11-10
  • 打赏
  • 举报
回复
每日一顶,希望有各位高手帮忙看下,谢谢
yaoshanghuan 2009-11-09
  • 打赏
  • 举报
回复
输出sql语句在查询分析器里面执行,可以正确的现实数据,。。

注释掉excel导出语句,在页面中现实也是一切正常,就是导出EXCEL的时候不行,有时候现实空数据,有时候就把所有的数据都导出来了。。
yaoshanghuan 2009-11-09
  • 打赏
  • 举报
回复
回复楼上2位,你们说的方法我都试过的,我把response.write执行的话输出的内容是正确的,是我想要的数据,,但是导出到 excel的时候就不对了。。。让我很郁闷,,
ACMAIN_CHM 2009-11-07
  • 打赏
  • 举报
回复
<%
kaishi=trim(request("kaishi"))
jieshu=trim(request("jieshu"))

sql="select * from dinggou where (1=1)"
if kaishi <>"" and jieshu <>"" then
sql=sql&" and (subtime between '"&kaishi&" 00:00:00' and '"&jieshu&" 23:59:59')"
end if

sql=sql&" order by id asc"
'response.write(sql)
'response.End()
set rs=conn.execute(sql)
%>

估计红这一段没执行。估计你的
kaishi=trim(request("kaishi"))
jieshu=trim(request("jieshu"))
变量名搞错了。

按一楼的,把sql的内容打出来看一下。
lzp4881 2009-11-07
  • 打赏
  • 举报
回复
应该是 kaishi和 jieshu 没有值,你可以把
'response.write(sql)
'response.End()
的单引号去掉,同时注释掉
Response.ContentType = "application/vnd.ms-excel"
看看输出什么

28,406

社区成员

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

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