如何从HTML表创建可下载的Excel表? [英] How do I create a downloadable excel sheet from an HTML-table?

查看:119
本文介绍了如何从HTML表创建可下载的Excel表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆