查看: 4544|回复: 3

[求代码] 求asp中多条件搜索后,将搜索结果(一般都有多条数据)导出为excel的代码

[复制链接]
想念熊 发表于 2016-2-16 09:36:23 | 显示全部楼层 |阅读模式
数据库是SQL,需要将符合搜索条件的结果(结果有多个)导出为excel,望各位指教。
xuanxiao 发表于 2016-4-4 14:39:29 | 显示全部楼层

  1. <!--#include file="../conn.asp"-->
  2. <%
  3. if session("china_admin")="" then response.redirect "login.asp"
  4. dbpath="../"
  5. dblink
  6. dim filename,fs,myfile,x,m,n,o,link
  7. Set fs = server.CreateObject("scripting.filesystemobject")

  8. Set rs = Server.CreateObject("ADODB.Recordset")
  9. session("sql") = "select * from china_car"
  10. rs.Open session("sql"),conn,1,1
  11. n=1

  12. '==================================================================
  13. '==============================================================建立excel文件系统
  14. filename = Server.MapPath("car/CarTable"&n&".xls") '这个是为了方便,新建一个CAR的文件夹,这个可以自己设啦
  15. if fs.FileExists(filename) then'如果文件存在,覆盖它。
  16. fs.DeleteFile(filename)
  17. end if
  18. set myfile = fs.CreateTextFile(filename,true)

  19. '========================================================================

  20. dim strLine,responsestr
  21. strLine=""

  22. dim work,j,i
  23. str="序号|卡号|密码|积分数|金额"  '这个根据你的access数据表字段设置。
  24. work=split(str,"|")
  25. j=ubound(work)
  26. i=0
  27. o=0
  28. do while not i>j
  29. strLine= strLine & work(i) & chr(9)
  30. i=i+1
  31. loop

  32. myfile.writeline strLine
  33. Do while Not rs.EOF
  34. o=o+1
  35. m=20000


  36. strLine=""

  37. for each x in rs.Fields
  38. strLine= strLine & x.value & chr(9)
  39. if o>=m*n then
  40. n=n+1
  41. filename = Server.MapPath("car/CarTable"&n&".xls") '这个可以自己设啦
  42. if fs.FileExists(filename) then'如果文件存在,覆盖它。
  43. fs.DeleteFile(filename)
  44. end if
  45. set myfile = fs.CreateTextFile(filename,true)
  46. end if
  47. next

  48. myfile.writeline strLine

  49. rs.MoveNext
  50. loop

  51. rs.Close
  52. set rs = nothing
  53. conn.close
  54. set conn = nothing
  55. set myfile = nothing
  56. Set fs=Nothing
  57. ExcelPath="car/CarTable"&n&".xls"
  58. response.Write "导出成功  "
  59. response.write("<a href='" & server.URLEncode(ExcelPath) & "'><font=red>下载</font></a>")

  60. %>
复制代码
嘉文 发表于 2016-7-22 00:35:02 | 显示全部楼层
这样的话,银行账号和身份证号码是科学计数显示的,请问该如何解决呢
xuanxiao 发表于 2016-7-22 15:50:02 | 显示全部楼层
这样的话,银行账号和身份证号码是科学计数显示的,请问该如何解决呢
嘉文 发表于 2016-7-22 00:35


在银行账号和身份证号前加上符号 '让他强制字符串输出就是了
EXCEL会自动识别为字符,而不是科学数字
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

在线客服

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