admin管理员组

文章数量:1609530

table2excel实例


  • 使用插件:table2excel.js
  • 简介:table2excel 可以转换和下载html上的表格,使他成为.xlsx格式,能够被Excel打开

实例代码

<head>
    <!--js文件在文章末尾-->
    <script src="table2excel.js"></script>
</head>

<body>

    <!--table属性:data-excel-name设置该table在Excel的sheet名称-->
    <table data-excel-name="Excel_sheet_name1">
        <thead>
        <tr>
            <th>table_head</th>
        </tr>
        </thead>
        <tbody>
            <tr>
                <td>table_data_cell</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td>table_foot_cell</td>
            </tr>
        </tfoot>
    </table>

    <table data-excel-name="Excel_sheet_name2">
        <thead>
        <tr>
            <th>table_head</th>
        </tr>
        </thead>
        <tbody>
            <tr>
                <td>table_data_cell</td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td>table_foot_cell</td>
            </tr>
        </tfoot>
    </table>

    <!--输出excel文件按钮-->
    <button id="export">Export_to_excel</button>
    <script>
        var table2excel = new Table2Excel();
        // table2excel.export(table, table_name), table_name是你要输出的table文件名
        document.getElementById('export').addEventListener('click',function(){
            table2excel.export(document.querySelectorAll('table'),'table_name');
        });
    </script>
</body>

相关链接

来源:https://www.npmjs/package/table2excel
Demo:https://rusty1s.github.io/table2excel/demo/
table2excel.js:上面script加载的文件(点击下载)
Github了解更多:github/rusty1s/table2excel

本文标签: 表格实例标签jshtml