用于将数据从Access数据库导出到Excel工作表的经典asp代码

时间:2017-07-27 10:35:41

标签: html asp.net database excel ms-access

我有一个运行在HTML页面的经典ASP编码中的应用程序,并且在一个.asp页面中客户端请求了一个按钮。单击此按钮时,它必须将Access of Access数据库(已在使用中)中存在的任何数据导出到Excel工作表。

1 个答案:

答案 0 :(得分:0)

您可以使用带有HTML表的xls扩展名生成一个文件,Excel将打开(带有警告)就好了。例如:

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>