Robert Eriksson Robert Eriksson - 1 month ago 6
HTML Question

How do I create a downloadable excel sheet from an HTML-table?

I have a table in HTML, like this:

<table>
<thead>
<tr>
<th>Column1</th>
<th>Column2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data1</td>
<td>Data2</td>
</tr>
</tbody>
</table>


I want to download this data in the form of an Excel-sheet. I've tried some "simple" methods of just opening the data in a new window like this:

javascript:window.open('data:application/vnd.ms-excel,'+document.documentElement.innerHTML);


But the actual table I want to export has too many lines and it crashes the browser..

Any ideas on how to solve this?

Clarification: I want to do this through a webpage, for examble using a button to trigger a function to create the excel sheet and start downloading it. Like this:

<button onclick="downloadExcelSheet()">Download the table as an excel sheet</button>

Answer

If this is off of a web server, you want to use the PHP Excel library

It can be found here: http://phpexcel.codeplex.com/

If for some reason you don't have the ability to run PHP scripts, please include more information in your post