【问题标题】:Export to Excel from HTML从 HTML 导出到 Excel
【发布时间】:2021-04-13 14:46:07
【问题描述】:

有没有办法从 HTML 表格导出到 excel。我在 .NET Core 应用程序中使用过 HTML 表格,需要用样式格式化表格,同样必须导出到 excel。

【问题讨论】:

    标签: html .net excel .net-core


    【解决方案1】:

    是的,您可以使用 Datatables 插件实现它

    <table id="example" class="display nowrap" style="width:100%">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Tiger Nixon</td>
                    <td>System Architect</td>
                    <td>Edinburgh</td>
                    <td>61</td>
                    <td>2011/04/25</td>
                    <td>$320,800</td>
                </tr>
            </tbody>
        <tfoot>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </tfoot>
        </table>
    <script src='https://code.jquery.com/jquery-3.5.1.js'></script>
    <script src='https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js'></script>
    <script>
    $(document).ready(function() {
        $('#example').DataTable( {
            dom: 'Bfrtip',
            buttons: [
                'csv', 'excel', 'pdf', 'print'
            ]
        } );
    } );
    </script>
    

    【讨论】:

      【解决方案2】:

      图书馆tableToExcel.517b1af9.js在这里https://github.com/linways/table-to-excel/blob/master/dist/tableToExcel.517b1af9.js

      <script src="/tableToExcel.517b1af9.js"></script>
      
      <script>
      TableToExcel.convert(document.getElementById("idTable"));
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-04
        相关资源
        最近更新 更多