【问题标题】:Angularjs exporting table and c3 charts to excel sheetAngularjs将表格和c3图表导出到excel表
【发布时间】:2016-07-04 08:42:25
【问题描述】:

在我的 Web 应用程序中,我需要将 html 表格和 c3 图表导出到 Excel 表格。我可以使用 FileSaver.js 将表格导出到 Excel,但我迷失了如何将表格和图表导出到一个 Excel 文件中。请给我任何建议或样品?谢谢。

【问题讨论】:

    标签: angularjs html-table export-to-excel c3.js


    【解决方案1】:

    检查此链接..

    export to excel

    fiddle here

        <script src="http://alasql.org/console/alasql.min.js"></script>
    <button onclick="window.exportCSV()">Export table to Excel</button>
    <table width="100%">
    <tr><th>Table 1</th><th>Table 2</th>
    <tr><td>
    <table  id="table1" border="1"  align="center" >
        <thead>
             <tr><th>ID</th><th >Name</th><th>Month</th><th>Savings</th></tr>
        </thead>
        <tbody>
             <tr><td>101</td><td>John</td><td>January</td><td>$100</td></tr>
             <tr><td>102</td><td>Rianna</td><td>Feb</td><td>$200</td></tr>
             <tr><td>103</td><td>Michael</td><td>Mar</td><td>$300</td></tr>
       </tbody>
    </table>
    <td>
      <table  id="table2" border="1" align="center" >
         <thead>
             <tr><th>ID</th><th >Name</th><th>Month</th><th>Savings</th></tr>
        </thead>
        <tbody>
             <tr><td>101</td><td>Valentin</td><td>January</td><td>$10000</td></tr>
             <tr><td>102</td><td>Olga</td><td>Feb</td><td>$20000</td></tr>
             <tr><td>103</td><td>Alesya</td><td>Mar</td><td>$300000</td></tr>
       </tbody>
      </table>
    

    window.exportCSV =    function exportCSV() {
        var data1 = alasql('SELECT * FROM HTML("#table1",{headers:true})');
        var data2 = alasql('SELECT * FROM HTML("#table2",{headers:true})');
        var data = data1.concat(data2);
        alasql('SELECT * INTO CSV("data.csv",{headers:true}) FROM ?', [data]);
    }
    

    我在我的项目中使用过这个.. 很酷:)

    【讨论】:

    • 这很酷。但我也需要导出c3折线图,连同表格。
    • 您可以将c3折线图值映射到一个不可见的表格中。然后将表格值导出到csv/excel。
    猜你喜欢
    • 2023-03-16
    • 2017-08-09
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多