如何从数据表的excel导出文件中的列数据中获取行标题名称和文件标题名称

时间:2019-05-24 16:15:39

标签: excel datatables

我正在尝试将供应商名称(列:PL1)用作我的excel文件名,并将其显示在我的excel文件的第一行中作为标题。下面是我的代码。

$(document).ready(function () {
    var mesa = $('.datatable').DataTable({
        filename: "Application",
        responsive: true,
        "bAutoWidth": false, // toggle this depending on how wide you want the table
        "ajax": {
            "url": "/ApplicationImportTgts/GetData",
            "type": "GET",
            "datatype": "json"
        },
        responsive: 'true',
        dom: 'Bfrtip',
        buttons: [
            'copy',
            {
                extend: 'excelHtml5',
                text: 'Excel',
}
            }, 'pdf'
        ],
        "columns": [
            { "data": "PARTNO" },
            { "data": "PARTNO" },
            { "data": "PartsName" },
            { "data": "QTY" },
            { "data": "PL1" },
            { "data": "PL2" },
            { "data": "MODEL" },
            { "data": "TYPE" },        
            { "data": "PL3" },
            { "data": "Discrepancies" },
            { "data": "Comments" }
        ],

        initComplete: function () { // After DataTable initialized
            this.api().columns([4]).every(function () {
                /* use of [2] for third column.  Leave blank - columns() - for all.
                Multiples? Use columns[0,1]) for first and second, e.g. */
                var column = this;
                var select = $('<select><option value=""/></select>')
                    .appendTo($('.datatable .dropdown .fifth').empty()) /* for multiples use .appendTo( $(column.header()).empty() ) or .appendTo( $(column.footer()).empty() ) */
                    .on('change', function () {
                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );

                        column
                            .search(val ? '^' + val + '$' : '', true, false)
                            .draw();
                    });
                column.data().unique().sort().each(function (d, j) {
                    select.append('<option value="' + d + '">' + d + '</option>')
                });
            }); // this.api function
        } //initComplete function

    });
});
$(window).resize(function () {
    $('.datatable').removeAttr('style');
});

我想从下拉列表中获取选定的PL1值,以在导出的excel文件中显示为标题行和该文件的标题名称。

0 个答案:

没有答案