查看: 1609|回复: 2

[求代码] 将从数据库中查询的内容导出excel内

[复制链接]
高云松 发表于 2019-4-4 18:39:46 | 显示全部楼层 |阅读模式
查询代码如下,该如何需改
<%
'session.timeout=6000
'Server.ScriptTimeOut=2000

dim conn,rs,sysConfig,db
db="../data/database.mdb" '数据库文件位置
set conn=server.createobject("adodb.connection")
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" &Server.MapPath(""&db&"")

Set rs = Server.CreateObject("ADODB.Recordset")
%>
<!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>无标题文档</title>
<style type="text/css">
body,td,th {
        font-size: 12px;
}
body {
        margin-left: 0px;
        margin-top: 0px;
        margin-right: 0px;
        margin-bottom: 0px;
        background-color: #9F0;
}
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="735" border="1" align="center" cellpadding="5" cellspacing="0">
    <tr>
   <% set rs=server.CreateObject("adodb.recordset")
   rs.open "select Points.PointID,Papername from Points,PointDCD where Points.PointID=PointDCD.PointID and Points.PaperID="&request("id")&"",conn,1,1
    %>
      <th height="10" colspan="3" scope="col"><%=rs("Papername")%></th>
    </tr>
    <tr>
      <th width="208" height="10" scope="col"><strong>教学目标编号</strong></th>
      <th width="251" scope="col">教学目标内容</th>
      <th width="250" scope="col">达成度</th>
    </tr>
    <tr>
      <%
  set rs=server.CreateObject("adodb.recordset")
  rs.open "select Points.PointID,PointDCD,PointName from Points,PointDCD where Points.PointID=PointDCD.PointID and Points.PaperID="&request("id")&"",conn,1,1
  do while not rs.eof
  %>
      <td><%=rs("PointID")%></td>
      <td><%=rs("PointName")%></td>
      <td><%=rs("PointDCD")%>%</td>
    </tr>
    <%
  rs.movenext
  loop
  rs.close
  set rs=nothing
  %>
  </table>
</form>
</body>
</html>
ttasp 发表于 2019-4-4 19:53:32 | 显示全部楼层
  1. <%
  2. Response.AddHeader "Content-Disposition", "attachment;filename=members.xls"
  3. Response.ContentType = "application/vnd.ms-excel"
  4. response.write "<table width='100%' border='1' >"
  5. response.write "<tr>"
  6. response.write "<th width='40%'><b>姓名</b></th>"
  7. response.write "<th width='30%'><b>昵称</b></th>"
  8. response.write "<th width='30%'><b>密码</b></th>"
  9. response.write "</tr>"
  10. response.write "<tr>"
  11. response.write "<td width='40%'>杨超越</td>"
  12. response.write "<td width='30%'>村花</td>"
  13. response.write "<td width='30%'>19980731</td>"
  14. response.write "</tr>"
  15. response.write "</table>"
  16. %>
复制代码


动态输出就行了,参考http://www.ttasp.net/article/2/11/201410/142.html
柳先生 发表于 2021-5-18 17:53:14 | 显示全部楼层
对的,
关键是这两句
Response.AddHeader "Content-Disposition", "attachment;filename=members.xls"
Response.ContentType = "application/vnd.ms-excel"
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号