ASP生成EXCEL

使用ASP实现将数据库内容写入EXCEL表格生成.xls文件的ASP代码

    <%
    dim path
    path=server.MapPath("client.xls")
    set fso=server.CreateObject("Scripting.filesystemobject")
    if fso.FileExists(path) then
    fso.deletefile(path)   
    end if  
    set myfile=fso.createtextfile(path,true)
    set rs=server.CreateObject("adodb.recordset")
    sql="select id,cname,caddress,ctelephone,cfax,cmobile,cemail,caddtime,xname,mcode,remark,saletel,website,qq,bank,bankname,bankid from client_info"
    rs.open sql,con,1,1
    if rs.EOF and rs.BOF then
       Response.Write "<div align=center>暂时没有数据!</div>"
    else
    dim strLine,responsestr
    strLine=""
    For each x in rs.fields
    strLine= strLine & x.name & chr(9)
    Next
    
    '--将表的列名先写入EXCEL
    myfile.writeline strLine
    
    Do while Not rs.EOF
    strLine=""
    
    for each x in rs.Fields
    strLine= strLine & x.value & chr(9)
    next
    '--将表的数据写入EXCEL
    myfile.writeline strLine
    
    rs.MoveNext
    loop%>
    <script>
    alert("导出成功!")
    location.href="client.xls"
    </script>
    <%
    end if
    rs.Close
    set rs = nothing
    set myfile = nothing
    Set fs=Nothing%>


「倘若有所帮助,不妨酌情赞赏!」

Holmesian

感谢您的支持!

使用微信扫描二维码完成支付


相关文章

发表新评论