Javascript Download to excel sheet
There is an HTML table as
<table>
<tr><th>NAME</th></tr>
<tr><td>SAL</td></tr>
<tr><td>TOM</td></tr>
<tr><td>SAM</td></tr>
<tr><td>J开发者_开发知识库enny</td></tr>
</table>
Download to excel sheet
On click hyperlink how to save the table to excel sheet
You might want to try using the XLSX.js lib http://blog.innovatejs.com/?tag=xlsx-js
There is an example there on how to export to excel which gives examples.
Note this exports to the XLSX format not XLS. But this should not be a problem for most use. The source is on GitHub: https://github.com/stephen-hardy/xlsx.js
You may want to take a look at table2CSV, since Excel can open csv files with no problem (and as a bonus other software can do it too, like OpenOffice). If you need it to be cross-browser, there's no way of generating a downloadable file, for that you need a server side script like the one in the example in the page I linked.
I have developed a product called scriptscraper which is designed to solve that problem.
Get the trial installed because the demonstration projects download data from yahoo finance and store the data in Excel. For that simple html table it would be no problem to do what you need.
Try this:
function makeSheet() {
var x = theTable.rows
var xls = new ActiveXObject("Excel.Application")
xls.visible = true
xls.Workbooks.Add
for (i = 0; i < x.length; i++){
var y = x[i].cells
for (j = 0; j < y.length; j++){
xls.Cells( i+1, j+1).Value = y[j].innerText
}
}
}
精彩评论