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

ag-grid-react 33.0.3版本Excel导出后文件损坏报错咨询

Ag Grid Excel导出文件损坏问题(版本33.0.3)

使用ag-grid-react@33.0.3实现Excel导出功能时,遇到文件损坏问题:

  • 下载生成的Report.xlsx后,Excel打开提示:

We found a problem with some content in Report.xlsx. Do you want us to try recover as much as we can? If you trust the source of this workbook, click Yes.

  • 查看恢复日志error200280_01.xml,内容如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error200280_01.xml</logFileName>
<summary>Errors were detected in file 'C:\Users\Filename.xlsx'</summary>
<repairedRecords>
<repairedRecord>Repaired Records: Cell information from /xl/worksheets/sheet1.xml part</repairedRecord>
</repairedRecords>
</recoveryLog>

自定义导出函数代码:

function exportToExcel(props, fileName) {
    // Validate and format data before exporting
    const processCellCallback = (params) => {
        let value = params.value;
        if (value) {
            // Ensure value is a string and remove any invalid characters
            value = value.toString().replace(/[^\x20-\x7E]/g, '');
        }
    return value;    
    };

    const params = {
        processCellCallback: processCellCallback,
        fileName: fileName,
        sheetName: fileName,    
    };
    props.api.exportDataAsExcel(params);
}

即使使用最简调用gridApi.exportDataAsExcel();,仍出现相同问题,已参考官方Excel默认导出示例。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 21:45:57