Asp classic 只需下载ASP文件

Asp classic 只需下载ASP文件,asp-classic,xls,Asp Classic,Xls,我有一个旧网站,我正试图采取下来,但在我这样做之前,我需要导出所有的数据。最初的站点设计包括一个ASP文件,该文件旨在从数据库表中获取数据并将其编译成excel文件,但当您单击站点上的链接时,它所做的只是下载ASP文件,它也只在IE或Edge上执行,而不是在Chrome上执行 代码如下所示,如有任何帮助,将不胜感激。我做了很多搜索,尝试了很多建议,但都没有成功 <% Response.ContentType = "application/vnd.ms-excel"%> <h

我有一个旧网站,我正试图采取下来,但在我这样做之前,我需要导出所有的数据。最初的站点设计包括一个ASP文件,该文件旨在从数据库表中获取数据并将其编译成excel文件,但当您单击站点上的链接时,它所做的只是下载ASP文件,它也只在IE或Edge上执行,而不是在Chrome上执行

代码如下所示,如有任何帮助,将不胜感激。我做了很多搜索,尝试了很多建议,但都没有成功

<%  Response.ContentType = "application/vnd.ms-excel"%>

<head>
<style type="text/css">
.style1 {
    text-align: left;
}
</style>
</head>

<!--#include file="../../low/connectDB.asp"-->
<!--#include file="../../low/functions.inc"-->



<body style="margin: 0">
<table style="width: 100%" cellpadding="4" cellspacing="0">
    <tr>
        <td colspan="10"><strong>Lake of the Woods Association, Inc.</strong></td>
    </tr>
    <tr>
        <td colspan="10"><strong>Schedule of Those Who Have Passed the LOWA Boat Certification 
                Course</strong></td>
    </tr>
    <tr>
        <td colspan="10"><strong>As of <%=date%></strong></td>
    </tr>
    <tr>
        <td style="width: 150"><strong>Type</strong></td>
        <td style="width: 250"><strong>First Name</strong></td>
        <td style="width: 250"><strong>Last Name</strong></td>
        <td style="width: 250"><strong>Address</strong></td>
        <td style="width: 120"><strong>Lot</strong></td>
        <td style="width: 120"><strong>Section</strong></td>
        <td style="width: 120"><strong>Course</strong></td>
        <td style="width: 120"><strong>VA Boat Id</strong></td>
        <td style="width: 120"><strong>Minutes</strong></td>
        <td style="width: 120"><strong>Grade</strong></td>
        <td style="width: 120"><strong>Status</strong></td>
    </tr>
<%  tottimes=1
    Set DB1 = Server.CreateObject("ADODB.Connection")
        DB1.Open(lowdbstring)
            Set RS1 = DB1.Execute ("SELECT * FROM course_applicants WHERE passfail = 'pass' ORDER BY MID ASC, grade DESC, ID DESC")  
                Do until RS1.EOF
                IF LSTMID<>RS1("MID") THEN
                    ncount=ncount+1
                    IF RS1("test_id") = "2" THEN
                        course="Short"
                    ELSE
                        course="Long"   
                    END IF

                    Set RS0 = DB1.Execute ("SELECT * FROM members WHERE ID = '"& RS1("MID") &"'")  
                        Do until RS0.EOF
                    IF RS0("mtype") = "G" THEN
                        mt="Guest"
                    ELSE
                        mt="Member" 
                    END IF


    %>  
                        <tr>
                            <td style="width: 150"><%=mt%></td>
                            <td style="width: 250"><%=RS0("fname")%></td>
                            <td style="width: 250"><%=RS0("lname")%></td>
                            <td style="width: 250"><%=RS0("address1")%></td>
                            <td style="width: 120"><%=RS0("lot")%></td>
                            <td style="width: 120"><%=RS0("section")%></td>
                            <td style="width: 120"><%=course%></td>
                            <td class="style1" style="width: 120"><%=RS1("VBcustID")%></td>
                            <td class="style1" style="width: 120"><%=RS1("tottesttime")%></td>
                            <td class="style1" style="width: 120"><%=FormatPercent(RS1("grade"),0)%></td>
                            <td class="style1" style="width: 120"><%=RS1("passfail")%></td>
                        </tr>
            <%          
                        RS0.MoveNext
                        loop
                    RS0.Close

                    tottimes=1
                    LSTMID=RS1("MID")
                    ELSE
                        tottimes=tottimes+1
                    END IF
                RS1.MoveNext
            loop
        RS1.Close
    DB1.Close       
%>
    </table>

在你的页面顶部试试这个

<%
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=whatever-you-want-to-call-it.xls"
%>

我应该补充一点,如果您使用的是Chrome,它会在Excel中启动文件之前要求您加载权限。我知道这并不能解决最初的问题,但我找到了一个解决方法。该网站有一个搜索引擎,最小长度为三个字符,我发现如果我输入三个下划线SQL通配符,那么我就可以将我需要的所有信息拉到搜索结果页面上,然后复制并粘贴到excel中


谢谢您的帮助。

我使用datatable导出到ms excel

试试这些页面


这似乎是经典的ASP,基于语法和文件扩展名?为什么要将其标记为ASP.NET?它们是完全不同的技术。我点击了错误的选项。据我所知,经典ASP或只是ASP没有现有的标记。是的,有。我已经把它添加到你的问题中。这看起来完全错了,为什么会有嵌套循环?当然,这两个查询应该合并在一起,我想这是一个充满错误的问题,人们可以帮助您解决。请删除Response.ContentType,并确保脚本在浏览器中正确输出。当它工作时,再次添加Response.ContentType和Response.AddHeader。谢谢您的建议。我以前试过这个。在Chrome上,我收到一条等待www…..org的消息,然后什么也没发生。在IE上,它只是说从站点下载,然后是一条错误消息,上面写着:在IE上,它只是说从站点下载,然后是一条错误消息,上面写着:Microsoft Excel无法访问文件……可能有几个原因。文件名或路径不存在该文件正被另一个程序使用您试图保存的工作簿与当前打开的工作簿同名。我认为在他们将其下载为csv之前,他们需要尝试将其作为HTML运行,并修复明显的代码问题。@LOWACommunications检查IIS服务器上是否存在MIME类型,您必须在提供任何内容之前添加它。