2
votes

I want to format certain cell values when right clicking the grid and choosing Export to Excel. I assume I'm going to use the processCellCallback function but how do I call it or override it?

I found the export function here this.gridOptions.api.exportDataAsExcel but I'm not sure how to connect the two, and I can't find any good examples at the ag-grid documentation.

This is what I've tried:

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;
        }
    }
}
1

1 Answers

3
votes

The processCellCallback and other options for exporting found on the page that you linked to, should be part of a params object that gets passed to the exportDataAsExcel function. Your set up should look more like this:

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)
}

Also, if you are using the enterprise features, there is a dedicated members forum and other resources available to you that let you have more dedicated support.