我的工作中有一些要求,包括使用 asp. 我们对此没有经验,而且我在 stackoverflow 的其他主题中找不到此问题的解决方案
问题是,如果我放
<% Option Explicit
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls"
%>
整个页面都会转到 Excel 文件。
我希望生成的 xls 文件中只包含一个表。
我想要的表是由这一行生成的:
<% =Result %>
如何实现这一目标?
thxxx
最佳答案
您的 URL 中需要包含一些内容,以使 XLS 版本的请求与标准版本不同。
通常,您可以使用查询字符串值来执行此操作,以便您的 URL 变为 http://yoursite.com/yourpage.asp?mode=xls
。
现在您可以在代码中使用:
<%
Option Explict
Dim result
''# Build Table into result variable
If Request.QueryString("mode") = "xls" Then
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls"
Else
%>
<html>
<!-- Normal HTML before the table here -->
<%
End If
Response.Write result
If Request.QueryString("mode") <> "xls" Then
%>
<!-- Normal HTML after the table -->
</html>
<%
End If
%>
如果您在页面中包含一行返回自身,并在末尾添加额外的 ?mode=xls
,用户将启动 excel,仅加载表格。
关于asp-classic - 仅导出经典 asp 页面中的 html 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11161893/