在Ag-grid上以正确的单元格格式导出到excel [英] Exporting to excel with proper cell formatting on ag-grid
问题描述
当我使用ag-grid自己的 exportDataAsExcel()
将表格导出到excel时,生成的excel包含日期为 General 而不是日期。
When I export a table to excel using ag-grid's own exportDataAsExcel()
the resulting excel contains dates as General data type instead of Date.
[]
我已经使用过:
exportDataAsExcel({
processCellCallback: ({col, val}) => {( /*date value formatting here*/ )}
})
可以同时格式化 Date
, string
和正确的日期格式(DD / MM / YYYY)
,但我无法使excel正确地将这些单元格识别为日期,而不是常规
to format both Date
, string
with proper date formatting (DD/MM/YYYY)
but I can't make excel properly recognize these cells as Date instead of General
这可以通过其网站上的excel导出示例进行复制: https://www.ag-grid.com/javascript-grid-excel/?framework=all#gsc.tab=0
This is reproducible with the excel export examples on their website: https://www.ag-grid.com/javascript-grid-excel/?framework=all#gsc.tab=0
推荐答案
我也使用此代码在excell中应用了值格式化程序:
I've used this code to apply value formatter in excell as well:
this.gridOptions.api.exportDataAsExcel({
processCellCallback: (params) => {
if (params.column.getColDef().valueFormatter) {
return params.column.getColDef().valueFormatter(params as any);
}
return params.value;
},
});
这篇关于在Ag-grid上以正确的单元格格式导出到excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!