导出到 Excel 时格式化单元格
Format cell when exporting to Excel
我想在右键单击网格并选择导出到 Excel 时设置某些单元格值的格式。我假设我将使用 processCellCallback
函数,但我该如何调用或覆盖它?
我在这里 this.gridOptions.api.exportDataAsExcel
找到了导出函数,但我不确定如何将两者联系起来,而且我在 ag-grid documentation.
找不到任何好的示例
这是我试过的:
this.gridOptions = <GridOptions>{
columnDefs: [{
// Here are my column definitions
}],
processCellCallback: function (params) {
console.log(params)
if (params.column.getColId() === 'Created' && params.value) {
return this.toDateTime(params.value);
} else {
return params.value;
}
}
}
在您链接到的页面上找到的 processCellCallback
和其他导出选项应该是传递给 exportDataAsExcel
函数的 params 对象的一部分。您的设置应该更像这样:
function myExcelExport () {
function formattingFunction (params) {
console.log(params)
if (params.column.getColId() === 'Created' && params.value) {
return this.toDateTime(params.value);
} else {
return params.value;
}
}
excelParams = {
...
processCellCallback: formattingFunction,
fileName: 'export.xls',
skipHeaders: true,
...
}
this.gridOptions.api.exportDataAsExcel(excelParams)
}
此外,如果您使用的是企业功能,可以使用 dedicated members forum and other resources 来获得更专业的支持。
我想在右键单击网格并选择导出到 Excel 时设置某些单元格值的格式。我假设我将使用 processCellCallback
函数,但我该如何调用或覆盖它?
我在这里 this.gridOptions.api.exportDataAsExcel
找到了导出函数,但我不确定如何将两者联系起来,而且我在 ag-grid documentation.
这是我试过的:
this.gridOptions = <GridOptions>{
columnDefs: [{
// Here are my column definitions
}],
processCellCallback: function (params) {
console.log(params)
if (params.column.getColId() === 'Created' && params.value) {
return this.toDateTime(params.value);
} else {
return params.value;
}
}
}
在您链接到的页面上找到的 processCellCallback
和其他导出选项应该是传递给 exportDataAsExcel
函数的 params 对象的一部分。您的设置应该更像这样:
function myExcelExport () {
function formattingFunction (params) {
console.log(params)
if (params.column.getColId() === 'Created' && params.value) {
return this.toDateTime(params.value);
} else {
return params.value;
}
}
excelParams = {
...
processCellCallback: formattingFunction,
fileName: 'export.xls',
skipHeaders: true,
...
}
this.gridOptions.api.exportDataAsExcel(excelParams)
}
此外,如果您使用的是企业功能,可以使用 dedicated members forum and other resources 来获得更专业的支持。