通过 TableExport.js 将表格上传到 Excel 时保持样式格式

2024-02-12

我在用着TableExport.js导出我的html表到Excel文件。我可以导出表格,但在 Excel 工作表中css正在失败。帮助我解决这个问题。我在用着inline仅CSS。我在下面附上了我的代码。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Table2csv Plugin</title>
    <link rel="shortcut icon" href="favicon.ico">
    <!-- <link href="css/table2csv.css" rel="stylesheet"> -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.0/xlsx.core.min.js"></script>
    <script src="FileSaver.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/TableExport/5.0.0/css/tableexport.css"></script>
    <script src = "https://cdnjs.cloudflare.com/ajax/libs/TableExport/5.0.0/js/tableexport.js"></script>
</head>
<body>


<table id="Population-list">
    <caption><h2>Countries by population</h2></caption>
    <thead>
    <tr>
        <th  bgcolor="#00FF00">Rank</th>
        <th  bgcolor="#00FF00">Country</th>
        <th  bgcolor="#00FF00">Population</th>
        <th  bgcolor="#00FF00">% of world population</th>
        <th  bgcolor="#00FF00">Date</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>1</td>
        <td  bgcolor="#00FF00">China</td>
        <td>1,370,570,000</td>
        <td>18.9%</td>
        <td>June 24, 2015</td>
    </tr>
    <tr>
        <td>2</td>
        <td  bgcolor="#00FF00">India</td>
        <td>1,273,140,000</td>
        <td>17.6%</td>
        <td>June 24, 2015</td>
    </tr>
    .
    .
    .
    .
    .
    .
    <tr>
        <td>8</td>
        <td  bgcolor="#00FF00">Bangladesh</td>
        <td>126,880,000</td>
        <td>2.19%</td>
        <td>June 24, 2015</td>
    </tr>
    <tbody>
</table>




<script>
    TableExport(document.getElementsByTagName("table"), {
    headers: true,                              // (Boolean), display table headers (th or td elements) in the <thead>, (default: true)
    footers: true,                              // (Boolean), display table footers (th or td elements) in the <tfoot>, (default: false)
    formats: ['xlsx', 'csv', 'txt'],            // (String[]), filetype(s) for the export, (default: ['xlsx', 'csv', 'txt'])
    filename: 'id',                             // (id, String), filename for the downloaded file, (default: 'id')
    bootstrap: false,                           // (Boolean), style buttons using bootstrap, (default: true)
    exportButtons: true,                        // (Boolean), automatically generate the built-in export buttons for each of the specified formats (default: true)
    position: 'bottom',                         // (top, bottom), position of the caption element relative to table, (default: 'bottom')
    ignoreRows: null,                           // (Number, Number[]), row indices to exclude from the exported file(s) (default: null)
    ignoreCols: null,                           // (Number, Number[]), column indices to exclude from the exported file(s) (default: null)
    trimWhitespace: true                        // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: false)
});
</script>

</body>
</html>

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 TableExport.js 将表格上传到 Excel 时保持样式格式 的相关文章

随机推荐