最近在写ag-grid-vue的项目 ,用到了导出Excel功能,但是导出的数据是原始数据,不怎么理想,后来找了点方法进行处理,导出效果很好
<AgGrid ... :defaultExcelExportParams="defaultExcelExportParams" ></AgGrid>
data () { return { ... defaultExcelExportParams: exportParams({ fileName: this.$route.meta.title }) // 导出文件名字配置 } }, export const exportParams = ({ fileName = 'export', sheetName = 'sheet1' }) => { return { fileName, sheetName, autoConvertFormulas: true, processCellCallback: (params) => { const colDef = params.column.getColDef() if (colDef.valueFormatter) { const valueFormatterParams = { ...params, data: params.node.data, node: params.node, colDef: params.column.getColDef() } return colDef.valueFormatter(valueFormatterParams) } return params.value } } }
报表结果:真香~
标签:vue,return,ag,excel,导出,valueFormatter,params,const,colDef From: https://www.cnblogs.com/bomdeyada/p/16648994.html