# 网页静态表格数据导出

# 效果

# 参考

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.net/jquery/1.10.2/jquery.min.js"></script>
    <script src="js/FileSaver.min.js"></script>
    <script src="js/xlsx.core.min.js"></script>
    <!-- 引入 tableexport.min.js 文件 -->
    <script src="https://cdn.jsdelivr.net/npm/tableexport@5.2.0/dist/js/tableexport.min.js"></script>

    <!-- 引入 tableexport.min.css 文件 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tableexport@5.2.0/dist/css/tableexport.min.css">


    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }

        table,
        th,
        td {
            border: 1px solid black;
        }

        th,
        td {
            padding: 8px;
            text-align: left;
        }
    </style>
</head>

<body>

    <h2>简单表格示例</h2>
    <button onclick="exportData()">导出</button>
    <table id="myTable">
        <thead>
            <tr>
                <th>姓名</th>
                <th>年龄</th>
                <th>城市</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>张三</td>
                <td>25</td>
                <td>北京</td>
            </tr>
            <tr>
                <td>李四</td>
                <td>30</td>
                <td>上海</td>
            </tr>
            <tr>
                <td>王五</td>
                <td>28</td>
                <td>广州</td>
            </tr>
        </tbody>
    </table>

</body>
<script>
    // 实例化
    var tableExport = TableExport($('#myTable'), {
        headers: true,
        footers: true,
        formats: ["xlsx"],
        filename: "id",
        bootstrap: false,
        exportButtons: true,
        position: "bottom",
        ignoreRows: null,
        ignoreCols: null,
        trimWhitespace: true,
        RTL: false,
        sheetname: "id",
        buttonContent: "自定义导出按钮文字"
    });
</script>


</html>

WARNING

需要导入这两个文件,请点击-群文件 (opens new window)-获取