簡體   English   中英

從Internet Explorer中的Javascript將HTML表格導出到Excel

[英]Exporting html table to excel from Javascript in Internet Explorer

我從客戶端的按鈕單擊事件獲得以下代碼。 它正在Chrome中打開Excel。 但是,在IE中,它只是附加到URL上,因此無法按預期運行。

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));
}

您可以在IE中將表更改為xml或csv。 因此,您的用戶可以使用excel打開它。 祝好運。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM