Javascript or Flash export to CSV/Excel

后端 未结 2 1541
我在风中等你
我在风中等你 2021-01-05 05:57

Is there anyway to export JSON data to CSV/Excel without any interaction with the server side? Using Javascript only? or Flash? I\'m currently using ZeroClipboard to copy th

2条回答
  •  滥情空心
    2021-01-05 06:26

    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.

    This is all the code that's required:

    $(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.

提交回复
热议问题