且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery表到CSV导出

更新时间:2022-12-31 09:38:45

找到一个有效的解决方案(在 http://www.topsemtips.com/2008/11/save-html- table-to-excel-using-jquery / ):

Found a solution that works (with help from http://www.topsemtips.com/2008/11/save-html-table-to-excel-using-jquery/):

我将函数更改为:

function popup(data) {
    $("#main div.inner").append('<form id="exportform" action="export.php" method="post" target="_blank"><input type="hidden" id="exportdata" name="exportdata" /></form>');
    $("#exportdata").val(data);
    $("#exportform").submit().remove();
    return true; 
}

并创建了文件export.php:

And created the file export.php:

<?php

    header("Content-type: application/vnd.ms-excel; name='excel'");
    header("Content-Disposition: filename=export.csv");
    header("Pragma: no-cache");
    header("Expires: 0");

    print $_REQUEST['exportdata'];

?>

更新:
IE7友好版本更多:

Update: A more IE7 friendly version:

<?php

    header('Content-Type: application/force-download');
    header('Content-disposition: attachment; filename=filename.csv');

    print $_POST['exportdata'];

?>