简体   繁体   中英

jQuery DataTable Excel Export

I have two questions regarding the jQuery DataTable Excel exporting described here: https://datatables.net/extensions/buttons/examples/initialisation/export.html

First, I have a dollar amount column in which negative numbers are enclosed by parenthesis. For example, -$5.00 displays as ($5.00). Is it possible when exporting to make Excel highlight the negative dollar amount values red without highlighting them in the table?

Another less pressing question that I'll ask while I'm here regards excluding certain columns from the export. As you can see below, I'm only exporting the first 8 columns and excluding all following columns. Is there a way to exclude columns based off of an associated class on a column or something similar without having to explicitly list the column numbers I want? Thanks.

$('#tblDetail').DataTable({
    dom: 'Bfrtip',
    buttons: [
    {
        extend: 'excel',
        text: 'Export to Excel',
        exportOptions: {
            columns: [0, 1, 2, 3, 4, 5, 6, 7]
        }
    }]
});

Another less pressing question that I'll ask while I'm here regards excluding certain columns from the export. As you can see below, I'm only exporting the first 8 columns and excluding all following columns. Is there a way to exclude columns based off of an associated class on a column or something similar without having to explicitly list the column numbers I want? Thanks.

You can add a class:

   <th class='notexport'>yourColumn</th>

them exclude by class:

$('#tblDetail').DataTable({
    dom: 'Bfrtip',
    buttons: [
    {
        extend: 'excel',
        text: 'Export to Excel',
        exportOptions: {
            columns: ':not(.notexport)'
        }
    }]
});

Regarding the selection of columns, you can use a column-selector which includes a "jquery selector" where you can use classes, ids, etc.

About the excel formatting, the excel buttons only includes raw data . Any other data, including formats, can't be transferred to excel As per the docs, though, you could try using the sheetJS library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM