Exporting html table to excel from Javascript in I

2019-08-21 06:00发布

I have the following code from button click event in client side. It is opening the excel in Chrome. However, in IE, it is just appending to the URL and it is not working as desired.

function generateexcel() {

    var table = document.getElementById("tsttable");

    var c = table.innerHTML;

    var html = c.trim()

    //add more symbols if needed...
    while (html.indexOf('á') != -1) html = html.replace('á', 'á');
    while (html.indexOf('é') != -1) html = html.replace('é', 'é');
    while (html.indexOf('í') != -1) html = html.replace('í', 'í');
    while (html.indexOf('ó') != -1) html = html.replace('ó', 'ó');
    while (html.indexOf('ú') != -1) html = html.replace('ú', 'ú');
    while (html.indexOf('º') != -1) html = html.replace('º', 'º');

    window.open('data:application/vnd.ms-excel,' + escape(html));
}

1条回答
地球回转人心会变
2楼-- · 2019-08-21 06:47

You can change your table to xml or csv in IE. So your user can open it with excel. Good Luck.

查看更多
登录 后发表回答