I have a HTML table in velocity template.
(我在力度模板中有一个HTML表。)
I want to export the html table data to excel using either java script or jquery, comatibale with all browser.(我想使用Java脚本或jquery将html表格数据导出到excel,并与所有浏览器兼容。)
I am using below script(我正在使用以下脚本)
<script type="text/javascript">
function ExportToExcel(mytblId){
var htmltable= document.getElementById('my-table-id');
var html = htmltable.outerHTML;
window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
}
</script>
This script works fine in Mozilla Firefox ,it pops-up with a dialog box of excel and ask for open or save options.
(该脚本可以在Mozilla Firefox中正常运行 ,它会弹出一个excel对话框,并询问打开或保存选项。)
But when I tested same script in Chrome browser it is not working as expected,when clicked on button there is no pop-up for excel.(但是,当我在Chrome浏览器中测试了相同的脚本时, 它无法按预期运行,当单击按钮时,Excel不会弹出。)
Data gets downloaded in a file with "file type : file" , no extension like .xls There are no errors in chrome console.(数据下载到文件名为“ file type:file”的文件中,没有扩展名,例如.xls。Chrome控制台中没有错误。)
Jsfiddle example :
(jsfiddle示例:)
http://jsfiddle.net/insin/cmewv/
(http://jsfiddle.net/insin/cmewv/)
This works fine in mozilla but not in chrome.
(在mozilla中工作正常,但在chrome中则不能。)
Chrome browser Test Case :
(Chrome浏览器测试用例:)
First Image:I click on Export to excel button
(第一张图片:我点击“导出到Excel”按钮)
and result :
(结果:)
ask by Sukane translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…