2

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

Jakuje
  • 24,773
  • 12
  • 69
  • 75
Rajeev
  • 44,985
  • 76
  • 186
  • 285

4 Answers4

3

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

wombling - Chris Paine
  • 1,651
  • 1
  • 18
  • 17
2

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.

cambraca
  • 27,014
  • 16
  • 68
  • 99
1

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.

Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
martsbradley
  • 148
  • 1
  • 9
  • Correct me if I am wrong ... runs as a stand-alone Windows process, as opposed to something that could be referenced from any old HTML page and used to open up Excel on the local system? Also, it looks like it's 35mb, yikes. – GregT Jun 07 '12 at 23:06
0

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
   }
  }
}
switz
  • 24,384
  • 25
  • 76
  • 101