如何将表格从网页导出为ex​​cel [英] How can I export tables to excel from a webpage

查看:100
本文介绍了如何将表格从网页导出为ex​​cel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将表格从一个网页导出为ex​​cel。我想导出包含所有的格式和颜色。

How can I export tables to excel from a webpage. I want the export to contain all the formatting and colours.

推荐答案

远离,最干净,是 Jquery DataTables表格工具插件。您可以通过网格对数据进行排序,过滤,排序和页面,并且只需要几行额外的代码和两个小文件,就可以导出到Excel,PDF,CSV,剪贴板和打印机。

Far and away, the cleanest, easiest export from tables to Excel is Jquery DataTables Table Tools plugin. You get a grid that sorts, filters, orders, and pages your data, and with just a few extra lines of code and two small files included, you get export to Excel, PDF, CSV, to clipboard and to the printer.

所有必需的代码:

  $(document).ready( function () {
    $('#example').dataTable( {
        "sDom": 'T<"clear">lfrtip',
        "oTableTools": {
            "sSwfPath": "/swf/copy_cvs_xls_pdf.swf"
        }
    } );
} );

所以,快速部署,没有浏览器限制,不需要服务器端语言,非常容易理解。这是一个双赢。

So, quick to deploy, no browser limitations, no server-side language required, and most of all very EASY to understand. It's a win-win. The one thing it does have limits on, though, is strict formatting of columns.

如果格式化和颜色是绝对破解者,那么只有100%可靠的跨浏览器方法发现是使用服务器端语言来处理您的代码中的正确的Excel文件。我的选择解决方案是 PHPExcel 这是我发现迄今为止唯一一个积极处理导出与格式化一个MODERN版本的Excel从任何浏览器,当你给它什么只是HTML。让我澄清一下,它绝对不像第一个解决方案那么容易,也是一个资源猪。然而,在正面它也可以直接输出到PDF。

If formatting and colors are absolute dealbreakers, the only 100% reliable, cross browser method I've found is to use a server-side language to process proper Excel files from your code. My solution of choice is PHPExcel It is the only one I've found so far that positively handles export with formatting to a MODERN version of Excel from any browser when you give it nothing but HTML. Let me clarify though, it's definitely not as easy as the first solution, and also is a bit of a resource hog. However, on the plus side it also can output direct to PDF as well. And, once you get it configured, it just works, every time.

更新 - 2016年9月15日: TableTools已停止支持一个名为按钮的新插件。这些工具执行的功能与旧的TableTools扩展相同,但是FAR更容易安装,并且它们可以使用现代浏览器的HTML5下载功能,可以支持不支持HTML5标准的浏览器的原始Flash下载。从我从2011年发布此响应以来的许多意见中可以看到,TableTools的主要弱点已经解决。我仍然不能推荐DataTable足够处理大量的数据,无论是对开发人员还是用户。

UPDATE - September 15, 2016: TableTools has been discontinued in favor of a new plugin called "buttons" These tools perform the same functions as the old TableTools extension, but are FAR easier to install and they make use of HTML5 downloads for modern browsers, with the capability to fallback to the original Flash download for browsers that don't support the HTML5 standard. As you can see from the many comments since I posted this response in 2011, the main weakness of TableTools has been addressed. I still can't recommend DataTables enough for handling large amounts of data simply, both for the developer and the user.

这篇关于如何将表格从网页导出为ex​​cel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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