rainabba / jquery-table2excel

jQuery Plugin to export HTML tabled to Excel Spreadsheet Compatible Files
595 stars 663 forks source link

The xls extension does not appear in IE9 #72

Open mustafarasit opened 7 years ago

mustafarasit commented 7 years ago

The xls extension does not appear in IE9.

`

`
rainabba commented 7 years ago

Can you elaborate a bit more please?

kristofermagic commented 7 years ago

fileext: ".XLS" it does not work. I have to put the extension file like I show you:

filename: "MyEXCEL_FILE.XLS"

rainabba commented 7 years ago

From README.md:

DISCLAIMER

This plugin is a hack on a hack. The .xls extension is the only way [some versions] of excel will even open it, and you will get a warning about the contents which can be ignored. The plugin was developed against Chrome and other have contributed code that should allow it to work in Firefox and Safari, but inconsistently since it's a hack that's not well supported anywhere but Chrome. I would not use this in public production personally and it was developed for an Intranet application where users are on Chrome and had known versions of Excel installed and the users were educated about the warning. These users also save-as in Excel so that when the files are distributed, the end-users don't get the warning message.

Also, IE9 is beyond ancient. No choice, but to support it (if it's even possible)?

isabas commented 7 years ago

Yeah, plugin is not adding ".xls" to filename at IE Edge with last version. Maybe, using filename "myexcel.xls" instead of "myexcel" it can be a solution for this issue. And u have to cross check for other browser.

isabas commented 7 years ago

https://github.com/rainabba/jquery-table2excel/blob/243fa8505fc60304662551fc4abc52853eb4ddad/src/jquery.table2excel.js#L154

After line 154 you can add this code.

        delete e.ctx.table;
        console.log("checking browser");
        var isIE = false;
        if (/MSIE 10/i.test(navigator.userAgent)) {
            // This is internet explorer 10
            isIE = true;
            console.log("10");
        }

        if (/MSIE 9/i.test(navigator.userAgent) || /rv:11.0/i.test(navigator.userAgent)) {
            // This is internet explorer 9 or 11
            isIE = true;
            console.log("9 or 11");
        }

        if (/Edge\/\d./i.test(navigator.userAgent)) {
            // This is Microsoft Edge
            isIE = true;
            console.log("edge");
        }

        if (isIE) {
            if (typeof Blob !== "undefined") {
                fullTemplate = e.format(fullTemplate, e.ctx); 
                fullTemplate = [fullTemplate];
                var blob1 = new Blob(fullTemplate, { type: "text/html" });
                window.navigator.msSaveBlob(blob1, getFileName(e.settings)+".xls");
            } else {
                txtArea1.document.open("text/html", "replace");
                txtArea1.document.write(e.format(fullTemplate, e.ctx));
                txtArea1.document.close();
                txtArea1.focus();
                sa = txtArea1.document.execCommand("SaveAs", true, getFileName(e.settings) + ".xls");
            }

        }
        else { ....... same code latest version....

i added ".xls extension "if browser is internet explorer.

i checked at edge, ie10. and plugin is working...