简体   繁体   English

Javascript / Jquery在Internet Explorer 10+中导出到Excel

[英]Javascript/Jquery export to Excel in Internet Explorer 10+

I've done lots of research and have come to a conclusion that its probably not possible to Export data to Excel using only the client side via Javascript/Jquery for Internet Explorer 10+ because it doesn't support the uri object. 我已经做了大量研究,得出的结论是,可能无法仅通过Internet Explorer 10+的Javascript / Jquery使用客户端将数据导出到Excel,因为它不支持uri对象。

Using only the client side, does anyone provide alternatives to handle a situation like this in IE? 仅使用客户端,是否有人提供替代方法来处理IE中的这种情况?

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

I recently had the same task and the solution I came with was this one: 我最近完成了相同的任务,随之而来的解决方案是:

function exportTable(myTable, filename) {
//IE
if (isIE()) {
    csvData = myTable;
    if (window.navigator.msSaveBlob) {
        var blob = new Blob([csvData], {
            type: "text/html"
        });
        navigator.msSaveBlob(blob, filename);
    }
} //other browser
else {
    window.open("data:application/vnd.ms-excel," + encodeURIComponent(myTable));
}}

Then called it in a way you like, something like: 然后以您喜欢的方式调用它,例如:

    $("#myButtonId").click(function (e) {
        exportTable($('#myTableId').html(), 'myFilename.xls');
    });

NB: I did not implement the filename option for other browsers. 注意:我没有为其他浏览器实现filename选项。

Hope this helps. 希望这可以帮助。

if uri is not working then use blob .Its working fine in IE 10 also. 如果uri无法正常工作,请使用blob。它在IE 10中也可以正常工作。 in place of URI use blob its working fine. 代替URI使用blob可以正常工作。 Use below code 使用以下代码

CSV is your data CSV是您的数据

var blob = new Blob([CSV], { type: 'text/csv' });
    if (navigator.msSaveBlob) { // IE 10+
        navigator.msSaveOrOpenBlob(blob, fileName + '.csv');
    } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM