简体   繁体   English

jQuery DataTable Excel导出

[英]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 我对此处描述的有关jQuery DataTable Excel导出有两个问题: 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). 例如,-$ 5.00显示为($ 5.00)。 Is it possible when exporting to make Excel highlight the negative dollar amount values red without highlighting them in the table? 导出时是否可以使Excel将负的美元金额值突出显示为红色而不在表中突出显示它们?

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. 正如您在下面看到的,我仅导出前8列,并排除所有后续列。 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. 正如您在下面看到的,我仅导出前8列,并排除所有后续列。 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. 关于列的选择,您可以使用包含“ jquery选择器”的列选择器 ,在其中可以使用类,id等。

About the excel formatting, the excel buttons only includes raw data . 关于excel格式, excel按钮仅包含原始数据 Any other data, including formats, can't be transferred to excel As per the docs, though, you could try using the sheetJS library. 但是,其他任何数据(包括格式) 都无法传输到excel 。根据文档,您可以尝试使用sheetJS库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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