[英]Export expandable table to excel file using Javascript
Im not to sure about the grouping in XLS but the main way we convert data into XL is to use CSV我不确定 XLS 中的分组,但我们将数据转换为 XL 的主要方式是使用 CSV
You can parse the data from your HTML into an array then export that array to CSV您可以将 HTML 中的数据解析为数组,然后将该数组导出为 CSV
Here is the code to make your html table downloadable to CSV这是使您的 html 表可下载为 CSV 的代码
var data = [ ['Foo', 'programmer'], ['Bar', 'bus driver'], ['Moo', 'Reindeer Hunter'] ]; function download_csv() { var csv = 'Name,Title\\n'; data.forEach(function(row) { csv += row.join(','); csv += "\\n"; }); console.log(csv); var hiddenElement = document.createElement('a'); hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv); hiddenElement.target = '_blank'; hiddenElement.download = 'people.csv'; hiddenElement.click(); }
<button onclick="download_csv()">Download CSV</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.