我已经使用 jQuery 从 html 表导出了一个 Excel 文件。虽然它导出得很好,但使用 Excel 打开它时显示以下错误
The file format and extension of 'download.xls' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?
我知道我们可以通过在服务器端创建 Excel 或禁用 extension hardening 来解决它。在系统注册表上。但由于可用资源有限,这两个选项都超出了我的范围,我只需要在客户端修复它。
Excel 输出示例:
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'><head><meta http-equiv="Content-type" content="text/html;charset=utf-8" />
<!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>My Worksheet</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
</head>
<body>
<table>
<thead>
<th>Name</th>
<th>Class</th>
</thead>
<tbody>
<tr>
<td>Name 1</td>
<td>Class 1</td>
</tr>
</tbody>
<table>
</body>
</html>
任何帮助将不胜感激。
最佳答案
我相信你不能,因为“.xls”文件实际上是由 HTML 和 CSS 组成的。这就是为什么它显示错误。您不会考虑使用“.CSV”来代替吗?
关于javascript - jQuery 导出的文件在 Excel 中打开时显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38582524/