How to convert html table to excel with multiple sheet?

后端 未结 8 1798
清歌不尽
清歌不尽 2020-11-28 05:53

How can I convert multiple html tables to an excel sheet with multiple worksheets? Could you please help into this.

My example https://jsfiddle.net/kdkd/5p22gdag/

8条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 06:25

    function tablesToExcel() {
            {
    
                var tab_text = document.getElementById("MsoNormalTable").outerHTML;
                var textRange; var j = 0;
                var tab = document.getElementById('MsoNormalTable'); // id of table
                var sa;
    
                var ua = window.navigator.userAgent;
                var msie = ua.indexOf("MSIE ");
                var txt = document.getElementById('txtArea1').contentWindow;
                if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
                {
                    txt.document.open("txt/html", "replace");
                    txt.document.write(tab_text);
                    txt.document.close();
                    txt.focus();
                    sa = txt.document.execCommand("SaveAs", true, "Say Thanks to Sumit.xls");
                }
                else                 //other browser not tested on IE 11
                    sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
    
                return (sa);
            }
     }
    
    
    

    It is working with IE7+ fine... :)

提交回复
热议问题