我想在Excel表格中打开HTML表格,而不必先保存Excel表格。我可以找到一些方法来首先在Excel表格中保存html表格,然后打开它。在excel中打开HTML表格,不保存为
我可以修改这些方法,也可以采用全新的方法。
这里是HTML我有截至目前(最小的用例来解释什么,我试过):
我尝试为演示创造的jsfiddle但似乎文件撰写不允许存在。不管这里是到fiddle的链接。
注意:我曾尝试过使用另一个选项,我已经找到并且不得不寻求帮助。这个问题的链接是here
请原谅我,如果我太困难,但我似乎无法通过冲浪找到解决方案,所以我正在尝试我发现哪些是类似的,但无法调整它。
function fnExcelReport() {
var tab_text = "
var textRange;
var j = 0;
tab = document.getElementById('tableData'); // id of table
for (j = 0; j < tab.rows.length; j++) {
tab_text = tab_text + tab.rows[j].innerHTML + "
";/*tab_text=tab_text+"";*/
}
tab_text = tab_text + "
";/*tab_text= tab_text.replace(/]*>|/g, "");//remove if u want links in your table*/
tab_text = tab_text.replace(/]*>/gi, ""); // remove if u want images in your table
tab_text = tab_text.replace(/]*>|/gi, ""); // reomves input params
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
{
txtArea1.document.open("txt/html", "replace");
txtArea1.document.write(tab_text);
txtArea1.document.close();
txtArea1.focus();
sa = txtArea1.document.execCommand("SaveAs", true, "download.xls");
} else //other browser not tested on IE 11
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
Heading2
Header1 | Header2 | Header3 | Header4 |
---|---|---|---|
Text1 | 93 | 4343 | 1243 |
Text2 | 103 | 26 | 4 |
Text3 | 932 | 67 | 3545 |
Text4 | 933 | 21348 | 7563 |
Text5 | 9383 | 576 | 230 |
Text6 | 9 | 354 | 345 |
Export To Excel
2017-03-03
300
+0
我创造了你的一个片段不工作,要么因为SO不允许弹出窗口 - PS为什么不看看为'txtArea1.document.execCommand'而不是测试IE useragent? –
+0
[这是链接到PLUNK,这似乎允许弹出窗口](http://plnkr.co/edit/Q6oCB8MiMmufmCliNdVT?p=preview) –
+0
那么这将永远不会工作:'txtArea1.document.open(“txt/html “,”它是text/html,但实际上并不是你想要的 –