用jQuery导出html-table

我想用javascript导出html表格的内容。

首先,我将遍历所有的TD元素,并收集数据,将其发送到另一个PHP页面,从而生成CSV-Excel。

或者我可以使用另一个框架,已经包含这个function?

这是一个有用的插件,将表转换为CSVstring。

可以使用window.open(MIMEtype,dataContainerItem)直接从浏览器导出html表格数据,而不需要进行服务器访问。 但是按照Web标准,它有一些限制,我们也无法处理输出文件的名称。 简单的步骤是 –

  1. 将你的html表格封装到一个容器(DIV)中。
  2. 将此容器(DIV)html的html内容与MIMEtypes一起传递给window.open。

恩。

window.open('data:application/vnd.ms-excel,' + encodeURIComponent( $('div[id$=divTableDataHolder]').html())); 

你可以参考 – http://codepattern.net/Blog/post/jQuery-export-table-data-into-MS-Excel

和极好的细节在其限制 – 导出到CSV使用jQuery和HTML

使用数据URI和table2CSV :

 var data = $table.table2CSV({delivery:'value'}); $('<a></a>') .attr('id','downloadFile') .attr('href','data:text/csv;charset=utf8,' + encodeURIComponent(data)) .attr('download','filename.csv') .appendTo('body'); $('#downloadFile').ready(function() { $('#downloadFile').get(0).click(); });