简体   繁体   中英

Classic asp code to export data from Access database to an Excel sheet

I have an application running in classic ASP coding with HTML pages and in one .asp page the client requested for a button. This button when clicked, it must export whatever the data present in a Table of Access database (already in use) to an excel sheet.

You can generate a file with the xls extension with an HTML table and Excel will open (with a warning) just fine. Example:

text.asp

<html>
<head>
</head>
<body>

<%

    Response.clear
    Response.ContentType = "application/vnd.ms-excel"
    Response.AddHeader "Content-Disposition", "attachment;filename=ExportedData.xls"
    Response.Write "<table>"
    Response.Write "<tr><th>User</th></tr>"

    set rs = ListUsers()
    if not rs.EOF Then
        Do while not rs.eof
            Response.Write "<tr><td>" + rs("User") + "</td></tr>"
            Rs.movenext
        loop
    end if


    Response.Write "</table>"
    Response.end
%>



</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM