小编Cam*_*341的帖子

使用 SheetJS 将动态创建的表格内容保存在 Excel 文件中

我动态地将行添加到 html 表中,并且想使用 SheetJs 将表内容保存到 xlsx 文件中。生成的文件是空的。当以这种方式添加表格内容时,是否可以在这种情况下做到这一点?我还尝试在创建 xlsx 文件之前添加行。

<!DOCTYPE html>
<html>

<head>
    <script src="https://code.jquery.com/jquery-2.1.4.js"
        integrity="sha256-siFczlgw4jULnUICcdm9gjQPZkw/YPDqhQ9+nAOScE4=" crossorigin="anonymous"></script>
    <script type="text/javascript"
        src="https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.15/plugins/export/libs/FileSaver.js/FileSaver.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.15.6/xlsx.full.min.js"></script>

    <style>
        table,
        td {
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.3/xlsx.full.min.js">
    </script>

    <p>Click the button to add a new row at the first position of the
        table and then add cells and content</p>

    <table id="myTable">
        <TR>
        </TR>
    </table>
    <button type="button" id="first" onclick="First('myTable')">Principal</button>
    <button id="button-a">Create Excel</button>
    <script>
        function First(tableID) {
            let table = document.getElementById(tableID)
            table.innerHTML …
Run Code Online (Sandbox Code Playgroud)

html javascript ajax jquery sheetjs

5
推荐指数
1
解决办法
1199
查看次数

标签 统计

ajax ×1

html ×1

javascript ×1

jquery ×1

sheetjs ×1