最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Javascript Download to excel sheet - Stack Overflow

programmeradmin5浏览0评论

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>Jenny</td></tr>
</table>

Download to excel sheet

On click hyperlink how to save the table 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>Jenny</td></tr>
</table>

Download to excel sheet

On click hyperlink how to save the table to excel sheet

Share Improve this question edited Jan 18, 2016 at 18:45 Jakuje 26k12 gold badges72 silver badges79 bronze badges asked Nov 16, 2010 at 5:22 RajeevRajeev 47k80 gold badges191 silver badges288 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

You might want to try using the XLSX.js lib http://blog.innovatejs./?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./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
   }
  }
}
发布评论

评论列表(0)

  1. 暂无评论