简体   繁体   English

使用Javascript从Destop应用程序导出到Excel

[英]Export to Excel from Destop application using Javascript

I have an application. 我有一个申请。 Please see the screenshot. 请看截图。 I need to Export table data to Excel using JavaScript. 我需要使用JavaScript将表数据导出到Excel。 I have tried to export table data with following JavaScript code 我尝试使用以下JavaScript代码导出表数据

function ExportToExcel(){
        var htmltable= document.getElementsByTagName("table")[0];
   var html = htmltable.outerHTML;
   window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
}

This code is working for a browser but for this application is not working. 该代码适用于浏览器,但不适用于该应用程序。

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

I think above line need to be change for native browser. 我认为上述行需要针对本机浏览器进行更改。 Anyone could help me please. 任何人都可以帮助我。 Thanks ! 谢谢 !

Remark : the author is referring to a "Native Browser" which in his case is a browser control that is embedded inside of another desktop software product. 备注 :作者指的是“本机浏览器”,在他的情况下是嵌入在另一个桌面软件产品内部的浏览器控件。

在此处输入图片说明

This function works for me in Chrome, Firefox. 此功能适用于Chrome,Firefox。 I am not sure about IE or Edge. 我不确定IE或Edge。

 function ExportToExcel() { var htmltable = document.getElementsByTagName("table")[0]; if (window.chrome && !window.opr) { // works for chrome var tableHtml = "<table border='1'>" + htmltable.innerHTML + "</table>"; var a = document.createElement('a'); a.href = 'data:application/vnd.ms-excel' + ', ' + table_html; a.download = "abc.xls'; //setting the file name a.click(); } else { var html = htmltable.outerHTML; window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html)); } } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM