Сохраняйте формат стиля при загрузке таблицы, чтобы преуспеть через TableExport.js - PullRequest
0 голосов
/ 20 ноября 2018

Я использую 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>
...