日期:2014-05-17  浏览次数:20883 次

如何将SQL数据库里面循环出的内容导出。
<!--#include file="include/function.asp"-->
<%
  response.charset = "GBK"  
 
if request.querystring("action")="toExcel" then  
  Response.ContentType="application/vnd.ms-excel"  
  Response.AddHeader "content-disposition","attachment;filename=aaa.xls"  
end if  
if request.querystring("action")="toWord" then  
  Response.ContentType="application/msword"  
  Response.AddHeader "content-disposition","attachment;filename=aaa.doc"  
end if  
%>
<!--#include file="include/conn.asp"-->

<%
  dim rs,sql
  if request.form("send") = "查询" then
  danwei = trim(request("danwei"))
  nian = trim(request("nian"))
  yue = trim(request("yue"))
  '查询该单位和年月有没有话费。
  set rs = server.createobject("adodb.recordset")
sql = "select * from Bill_hftj where danwei_sid ='"&trim(request("danwei"))&"' and hftj_year='"&trim(request("nian"))&"' and hftj_month='"&trim(request("yue"))&"' "
rs.open sql,conn,1,1
  if rs.eof then
  call sussLocationHref("没有查询的话费!","danwei_user_hfcx.asp")
  call close_rs
  call close_conn
  end if
  end if
  '开始分页
set rs = server.createobject("adodb.recordset")
sql = "select * from Bill_hftj where danwei_sid ='"&trim(request("danwei"))&"' and hftj_year='"&trim(request("nian"))&"' and hftj_month='"&trim(request("yue"))&"' "
rs.open sql,conn,1,1
dim allpage,page
'设置每页多少条
rs.pagesize = 15

'总页数
allpage = rs.pagecount

'总条数
allcount = rs.recordcount

'接收传过来的page页码
page = request.querystring("page")

'一开始进入,没有传page值,那么page就是空值,所以可以设置为第一页1
if page = "" then page = 1

'判断如果不是数字,那么page = 1
if isnumeric(page) then
'如果是0或者负数,那么page还是1 cint是整型,clng是长整形
if clng(page) <1 then page = 1
'如果page大于最大的分页数,那么就是最后一页
if clng(page) > rs.pagecount then page = rs.pagecount
else
page = 1
end if

'当前页码
if not rs.eof then
rs.absolutepage = page
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>V1.0版</title>

</head>
<body>
<table border="1" id="userjfcx">
<tr><th>电话号码</th><th>国内</th><th>区内</th><th>区间</th><th>总金额</th><th>话费年月</th></tr>
<%
  for i = 1 to rs.pagesize
if rs.eof then exit for '如果最后一页不足每面的显示条数,则要退出循环。  
%>
<tr><td><%=rs("Cent_Short")%></td><td><%=rs("Total_guonei")%></td><td><%=rs("Total_qunei")%></td><td><%=rs("Total_qujian")%></td&g