文件格式或文件扩展名无效
File format or File extension not valid
我正在使用rainabba/jquery-table2excel将html表导出到excel。单击按钮后,文件会被下载,但excelles报告文件或格式已损坏。请提出建议。
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript" src="jquery-table2excel-master/dist/jquery.table2excel.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e){
$("#myButton").click(function (e){
$(".mytable").table2excel({
name:"new File",
filename:"work",
//fileext:".xlsx"
});
});
});
</script>
</head>
<body>
<button id="myButton">Click To Download</button>
<table class="mytable" border="1">
<tr>
<th>new1</th>
<th>new2</th>
<th>new3</th>
<th>new4</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
</body>
</html>
<button class="btn btn-default" onclick="tableToExcel(''#divId'', ''Excel Report'')">Generate Excel</Button>
<div id="divId">
<table class="mytable" border="1">
<tr>
<th>new1</th>
<th>new2</th>
<th>new3</th>
<th>new4</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
</div>
var tableToExcel = (function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<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><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{('w+)}/g, function (m, p) { return c[p]; }) }
return function (table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
window.location.href = uri + base64(format(template, ctx))
}
})()
使用此代码。。用于生成excel文件。。
相关文章:
- 如何使用JavaScript粘贴原始二进制文件而不出现“无效字符”错误
- 数组在手动写入时有效,但从文本文件加载时无效
- 在Rails中使用remote:true在Chrome中有效,但在Safari中无效——从js.erb文件调用succe
- js.erb文件中提供给RegExp构造函数的标志无效
- Apache poi XSSF创建Excel文件-Create返回格式或文件扩展名无效的空文件
- 异步HTTP(ajax)请求在脚本标记中有效,但在js文件中无效
- 当SVG是单独的文件时,剪辑路径/web工具包掩码有效,但在内联时无效
- Jquery文件大小验证无效
- 无效文件的 Blueimp 文件上传错误消息
- 包括来自外部文件的jQuery,有些函数有效,有些则无效
- 如何删除在 Ajax文件上传上出现无效格式的默认警报
- 我不断得到空白值和无效文件
- 将包含内容和元数据的文件上传到谷歌文档会返回400无效/错误请求
- document.write在appendChild添加的Javascript文件中无效
- HTML5异步文件上传,上传的流总是无效的
- 内联javascript有效,但外部文件无效
- 脚本在html中有效,但在javascript文件中无效
- 使用jQuery表单插件上传文件-无效文件错误
- AJAX为HTML表单调用PHP文件无效
- 通过JavaScript上传文件:服务器上的文件无效