将html表导出到csv

时间:2014-02-13 12:24:52

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

我有一个示例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格式导出​​同一个表?

1 个答案:

答案 0 :(得分:0)

浏览以下链接。您将获得解决方案

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