如何从HTML表创建可下载的Excel表? [英] How do I create a downloadable excel sheet from an HTML-table?
问题描述
< table>
< thead>
< tr>
< Th> Column1< / th>
< Th> Column2< / th>
< / tr>
< / thead>
< tbody>
< tr>
< td> Data1< / td>
< td> Data2< / td>
< / tr>
< / tbody>
< / table>
我想以Excel表格的形式下载这些数据。我尝试过一些简单的方法,只需打开一个新窗口中的数据:
javascript:window.open ( '数据:应用程序/ vnd.ms-Excel中,' + document.documentElement.innerHTML);
但是我想要导出的实际表格太多,并且会导致浏览器崩溃。 p>
有关如何解决这个问题的任何想法?
澄清:我想通过一个网页来做这个,一个按钮来触发一个功能来创建excel表并开始下载它。像这样:
< button onclick =downloadExcelSheet()>以excel表格下载表格< / button>
如果这是脱离Web服务器,使用PHP Excel库
可以在这里找到: http ://phpexcel.codeplex.com/
如果由于某些原因您无法运行PHP脚本,请在您的帖子
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>
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
这篇关于如何从HTML表创建可下载的Excel表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!