Html Response.ContentType 应用程序/vnd.ms-excel xls 停止工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38466169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Response.ContentType application/vnd.ms-excel xls stopped working
提问by Chris Boozer
I've done some pretty deep searching on this issue with no luck. It seems that in the past couple of days the output to XLS from HTML has stopped working on many legacy (read: Classic ASP) systems I support. I've been able reproduce this on multiple servers, multiple independent source code from Office 2010 through Office 2016. I've looked at everything I can think of without success so I'm curious to know if there is something I might be overlooking. I'm starting to think this may be a bad Office update that is the culprit.
我在这个问题上做了一些非常深入的搜索,但没有运气。在过去的几天里,从 HTML 到 XLS 的输出似乎在我支持的许多遗留(阅读:经典 ASP)系统上停止工作。我已经能够在多个服务器上重现这一点,从 Office 2010 到 Office 2016 的多个独立源代码。我已经查看了我能想到的所有内容,但没有成功,所以我很想知道是否有我可能忽略的东西。我开始认为这可能是罪魁祸首的不良 Office 更新。
Sample of what works and has been working for many years:
有效且已工作多年的示例:
<%
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=TestExcel.xls"
%>
<html>
<body>
<table>
<thead>
<tr>
<th>column 1 header</th>
<th>column 2 header</th>
</tr>
</thead>
<tbody>
<tr>
<td>column 1 value</td>
<td>column 2 value</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Footer 1</td>
<td>Footer 2</td>
</tr>
</tfoot>
</table>
</body>
</html>
What is curious is that the XLS file is in fact created but when it is opened Excel opens but not file is present.
奇怪的是,实际上创建了 XLS 文件,但是当它打开时,Excel 打开但不存在文件。
Even more curious is that when you open the XLS file with some text editor (notepad for example) and just File->Save As it opens without issue.
更奇怪的是,当您使用一些文本编辑器(例如记事本)打开 XLS 文件时,只需 File->Save As,它就会毫无问题地打开。
回答by xelvis42
The issue is related to Microsoft Security Update KB3115262 for Excel that was released July 12, 2016. The security update information can be found in Microsoft Security Bulletin MS16-088 - Critical.
该问题与 2016 年 7 月 12 日发布的适用于 Excel 的 Microsoft 安全更新 KB3115262 相关。可在 Microsoft 安全公告 MS16-088 - 严重中找到安全更新信息。
I've found three workarounds (in my order of preference):
我发现了三种解决方法(按我的偏好顺序):
- Instead of clicking Open, save the file and then open it
- In Excel Trust Center > Trust Center Settings > Protected View, uncheck the top two options. This is potentially unsafe.
- Uninstall the security update.
- 不要单击“打开”,而是保存文件然后打开它
- 在 Excel 信任中心 > 信任中心设置 > 受保护的视图中,取消选中前两个选项。这可能是不安全的。
- 卸载安全更新。
Below are several links regarding the issue for further perusal. https://social.technet.microsoft.com/Forums/en-US/d2d84793-9920-45e3-baef-5027a4ac1ae0/kb3170008-for-office-2016-breaks-functionality-ms16088?forum=officeitpro
以下是有关该问题的几个链接以供进一步阅读。 https://social.technet.microsoft.com/Forums/en-US/d2d84793-9920-45e3-baef-5027a4ac1ae0/kb3170008-for-office-2016-breaks-functionality-ms16088?forum=officeitpro
https://technet.microsoft.com/library/security/MS16-088
https://technet.microsoft.com/library/security/MS16-088
回答by Tincho
You can also go to properties of the file and click Unblock.
您还可以转到文件的属性并单击取消阻止。
I think is safer than change the Excel Trust Center
我认为比更改 Excel 信任中心更安全
回答by CAK2
For Windows 10 users, add the Excel download site URL to your list of Trusted Sites in Windows 10 Internet Options > Security > Trusted Sites > Sites then download and open the Excel Workbook via your MS Edge browser.
对于 Windows 10 用户,将 Excel 下载站点 URL 添加到 Windows 10 Internet 选项 > 安全 > 受信任站点 > 站点中的受信任站点列表,然后通过 MS Edge 浏览器下载并打开 Excel 工作簿。