2013-07-13 30 views
0

我從客戶端的按鈕單擊事件中獲得以下代碼。它在Chrome中打開了excel。但是,在IE中,它只是追加到URL中,並且不能按需要工作。從Internet Explorer中的Javascript導出html表格以優化

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

http://caniuse.com/datauri – bfavaretto

+0

那麼在客戶端有沒有其他方式,或者我必須轉移到服務器端解決方案? – user2465036

+0

我相信你應該這樣做服務器端,但也許有一種方法...讓我們看看是否有人回答。 – bfavaretto

回答

0

您可以在IE中將表格更改爲xml或csv。所以你的用戶可以用excel打開它。祝你好運。