You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除DataTable导出Excel时的“Data Export”表头

解决DataTable导出Excel时移除“Data Export”表头的方法

你遇到的这个“Data Export”表头,就是配置里title: 'Data export'生成的,有两种处理方式:

方法一:直接移除title配置

如果不需要导出文件里有任何标题,直接删掉按钮配置中的title属性即可:

$('#example').DataTable({
    dom: 'Bfrtip',
    buttons: [
        {
            extend: 'excelHtml5',
            text: 'Download Excel' // 移除了title配置项
        }
    ],
    "autoWidth": false,
    "columns": [
        { "width": "20%" },
        { "width": "20%" },
        { "width": "20%" },
        { "width": "10%" },
        { "width": "15%" },
        { "width": "15%" }
    ]
});

方法二:通过customize自定义导出内容(保留按钮文字但移除导出标题)

如果想保留按钮上的“Download Excel”文字,但不想导出文件里出现标题,就用customize函数修改Excel的工作簿内容,移除标题行:

$('#example').DataTable({
    dom: 'Bfrtip',
    buttons: [
        {
            extend: 'excelHtml5',
            text: 'Download Excel',
            title: 'Data export',
            customize: function(xlsx) {
                var sheet = xlsx.xl.worksheets['sheet1.xml'];
                // 移除导出文件中的第一行标题
                $('row:first', sheet).remove();
            }
        }
    ],
    "autoWidth": false,
    "columns": [
        { "width": "20%" },
        { "width": "20%" },
        { "width": "20%" },
        { "width": "10%" },
        { "width": "15%" },
        { "width": "15%" }
    ]
});

这样修改后,导出的Excel文件就不会再出现那个“Data Export”的表头单元格了。

内容的提问来源于stack exchange,提问作者Rizal Maulana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 23:04:55