jquery - table2excel:Excel 文件已下载但未在 msoffice 中打开
问题描述
我编写了以下代码以在 excel 中下载表格。它已下载但在 ms-office 中该文件未打开。请检查所附屏幕截图中的错误。请指导我解决问题。
<!DOCTYPE html>
<html>
<head>
<title>jQuery Boilerplate</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js" type="text/javascript"></script>
<script src="https://rawgit.com/unconditional/jquery-table2excel/master/src/jquery.table2excel.js"></script>
</head>
<body>
<table class="table2excel" data-tableName="Test Table 2">
<thead>
<tr class="noExl"><td>This shouldn't get exported</td><td>This shouldn't get exported either</td></tr>
<tr><td>This Should get exported as a header</td><td>This should too</td></tr>
</thead>
<tbody>
<tr><td>data1a</td><td>data1b</td></tr>
<tr><td>data2a</td><td>data2b</td></tr>
</tbody>
<tfoot>
<tr><td colspan="2">This footer spans 2 cells</td></tr>
</tfoot>
</table>
<button class="exportToExcel">Export to XLS</button>
<script>
$.noConflict();
jQuery(document).ready(function($){
$(".exportToExcel").click(function(e){
var table = $(this).prev('.table2excel');
if(table && table.length){
var preserveColors = (table.hasClass('table2excel_with_colors') ? true : false);
$(table).table2excel({
exclude: ".noExl",
name: "Excel Document Name",
filename: "myFileName",
fileext: ".xls"
});
}
});
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</body>
</html>
解决方案
更新后查了一下发现
jquery.table2excel.js
文件它工作正常。完成后,您可以从此处下载表格到 excel , 只需将您的 jquery.table2excel.js 替换为下载的文件。希望它的工作。
推荐阅读
- python - 如何在 vscode 中将目录标记为源?尝试了所有可能的解决方案,没有任何效果
- mongodb - 非法指令(核心转储)mongodb Ubuntu 20.04 LTS
- javascript - 如果一个数据填充在 ui 中反应本机,如何在下拉列表和选择中填充数组值
- windows - 我的批处理文件没有我想要的那么快
- flutter - 如何将复杂的嵌套 Json 作为来自 Flutter 的 http post 请求发送到正文中
- windows - Windows bash 中的错误/非法格式或缺少 url
- string - 对文本文件中的所有字符进行操作的更快方法
- azure - PnP.Framework.AuthenticationManager 与 ConfidentialClientApplicationBuilder
- jquery - 双向滚动时隐藏固定菜单
- symfony - 如何在 Symfony 项目中找到所有带有特定注释的类?