【问题标题】:Export the html table to csv将 html 表导出为 csv
【发布时间】:2014-02-13 12:24:52
【问题描述】:

我有一个示例fiddle here,我可以在其中将 html 表格打印为 pdf 格式,

function printpage() {
    var data = '<table border="1" cellspacing="0"><tr><td colspan="4">Sample Report</td></tr>' + document.getElementsByTagName('table')[0].innerHTML + '</table>';
    data += '<br/><button onclick="window.print()"  class="noprint">Print the Report</button>';
    data += '<style type="text/css" media="print"> .noprint {visibility: hidden;} </style>';
    myWindow = window.open('', '', 'width=800,height=600');
    myWindow.innerWidth = screen.width;
    myWindow.innerHeight = screen.height;
    myWindow.screenX = 0;
    myWindow.screenY = 0;
    myWindow.document.write(data);
    myWindow.document.close();
    myWindow.focus();
}

如何在打印预览页面中再添加一个按钮,我可以使用它以 csv/xls 格式导出同一个表格?

【问题讨论】:

标签: javascript csv printing html-table export-to-csv


【解决方案1】:

通过下面的链接。你会得到解决方案

  `http://jsfiddle.net/terryyounghk/KPEGU/`  

【讨论】:

  • 无法下载标题行
  • 只为表格行编写代码。不适用于标题。可以看到第 3 行 var $rows = $table.find('tr:has(td)'),
  • 如何为下载的文件命名为download以外的其他名称?
猜你喜欢
  • 2013-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-27
  • 2011-11-01
  • 2017-11-23
相关资源
最近更新 更多