导出为 CSV 的数据表和缺少 Excel 文件扩展名

Datatables Export to CSV and Excel File Extension Missing

我关注了以下example。但是,每当我单击 CSV 和 Excel 文件导出按钮时,我只会得到一个没有扩展名的文件。我的最终用户手动添加文件扩展名会很麻烦,所以我想知道是否有什么需要修复的。我已经阅读了示例中的源代码,但没有发现任何不同之处。创建 table 的源代码非常简单。

$('#example').DataTable( {
    dom: 'Bfrtip',
    buttons: [
        'copy', 'csv', 'excel', 'pdf', 'print'
    ]
} );

非常感谢您的帮助。

我发现我需要将标题和扩展选项添加到 table 代码中。如果缺少其中任何一个,我将得到一个没有适当扩展名的文件。

$('#example').DataTable( {
    dom: 'Bfrtip',
    buttons: [
        'copy', 
        {
            extend: 'csv',
            text: 'csv',
            extension: '.csv',
            exportOptions: {
                modifier: {
                    page: 'current'
                }
            },
            title: 'table'
        }, 
        'pdf', 
        'print',
        {
            extend: 'excel',
            text: 'excel',
            extension: '.xlsx',
            exportOptions: {
                modifier: {
                    page: 'current'
                }
            },
            title: 'table'
        }
    ]
} );

一个解决方案,

 "aButtons": [
                {
                "oSelectorOpts": { filter: 'applied', order: 'current' },
                "sExtends": "copy",
                "sButtonText": "Copiar en Portapapeles"
                },
                {
                    "oSelectorOpts": { filter: 'applied', order: 'current' },
                    "sExtends": "xls",
                    "sButtonText": "Excel",
                    "sFileName": "*.xls" // <-- ADD THIS LINE

                },

                {
                    "oSelectorOpts": { filter: 'applied', order: 'current' },
                    "sExtends": "pdf",
                    "sPdfOrientation": "landscape",
                    "sPdfMessage": "RegES - Reportes ", 
                },
                "print"
            ]
        },