Larbear
Larbear

Reputation: 141

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.

Using only the client side, does anyone provide alternatives to handle a situation like this in IE?

Any help would be greatly appreciated. Thanks!

Upvotes: 1

Views: 2259

Answers (2)

tanuk
tanuk

Reputation: 528

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.

Hope this helps.

Upvotes: 1

Manish Patel
Manish Patel

Reputation: 11

if uri is not working then use blob.Its working fine in IE 10 also. in place of URI use blob its working fine. Use below code

CSV is your data

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

Upvotes: 0

Related Questions