following is the function i have used for exporting file: excelStyles: [ { id: 'header', interior: { color: '#aaaaaa', pattern: 'Solid', }, }, { id: 'body', dataType : 'string', interior: { color: '#dddddd', pattern: 'Solid', }, }, ]
function exportToExcel (){ var sheetNameVal = "Btest";
var params = {
skipPinnedTop : false,
sheetName : sheetNameVal
}
params.processCellCallback = function(params) {
var val = params.value ;
if(/^\d+$/.test(val))
val = " "+val;
else if(params.column.colDef.dataType=="Date/Time"){
if(val)
val = val.length>10 ? val.substring(0,10) : val;
}else if(!_.isEmpty(params.column.colDef.refData)){
val = params.column.colDef.refData[val];
}
if((params.column.colDef.field).includes("_TRX_AMT")){
var trxCurr = params.node.data.TRX_CURRENCY ;
val = FormatCurrency2(val,trxCurr);
}
return val;
};
gridOptions.api.exportDataAsExcel(params);
}
now if suppose one of my cell has value = '000000180' when i export it to excel the value is changed to 180. i have tried converting it to string using val = " "+val but somehow it didn't work.
You can set the type of the excelStyle to String:
https://www.ag-grid.com/angular-data-grid/excel-export-data-types/
As an alternative, instead of adding a " ", you can add "'" in front of your value.
The character ' will not be visible in Excel.