<% 响应。内容类型 = "application/vnd.ms-excel" %> 只需下载 ASP 文件



我有一个旧网站,我试图删除它,但在我这样做之前,我需要导出所有数据。原始网站设计包括一个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中。

感谢您的帮助。

我使用数据表导出到MS Excel

试试这些页面。

https://datatables.net/extensions/buttons/examples/initialisation/export.html

最新更新