From 076864a58ab2cb1b1df85ca09f276e651b06f0d9 Mon Sep 17 00:00:00 2001 From: Austin Simpson Date: Fri, 9 Dec 2022 16:35:09 -0800 Subject: [PATCH] feat: Excel exporter will now observe if numeric type has dollar formatter. If it does, it will use the dollarFormatter stylesheet. --- .../excel-export/src/excelExport.service.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/excel-export/src/excelExport.service.ts b/packages/excel-export/src/excelExport.service.ts index e869f0be7..d9708bcaa 100644 --- a/packages/excel-export/src/excelExport.service.ts +++ b/packages/excel-export/src/excelExport.service.ts @@ -17,6 +17,8 @@ import { ExternalResource, FileType, FieldType, + Formatter, + Formatters, GridOption, KeyTitlePair, Locale, @@ -233,7 +235,7 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ } /** use different Excel Stylesheet Format as per the Field Type */ - useCellFormatByFieldType(data: string | Date | moment_.Moment, fieldType: typeof FieldType[keyof typeof FieldType]): ExcelCellFormat | string { + useCellFormatByFieldType(data: string | Date | moment_.Moment, fieldType: typeof FieldType[keyof typeof FieldType], formatter?: Formatter): ExcelCellFormat | string { let outputData: ExcelCellFormat | string | Date | moment_.Moment = data; switch (fieldType) { case FieldType.dateTime: @@ -272,7 +274,17 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ case FieldType.number: const num = parseFloat(data as string); const val = isNaN(num) ? null : num; - outputData = { value: val, metadata: { style: this._stylesheetFormats.numberFormatter.id } }; + + switch (formatter) { + case Formatters.dollar: + case Formatters.dollarColored: + case Formatters.dollarColoredBold: + outputData = { value: val, metadata: { style: this._stylesheetFormats.dollarFormatter.id} }; + break; + default: + outputData = { value: val, metadata: { style: this._stylesheetFormats.numberFormatter.id } }; + break; + } break; default: outputData = data; @@ -583,7 +595,7 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ // use different Excel Stylesheet Format as per the Field Type if (!columnDef.exportWithFormatter) { - itemData = this.useCellFormatByFieldType(itemData as string, fieldType); + itemData = this.useCellFormatByFieldType(itemData as string, fieldType, columnDef.formatter); } rowOutputStrings.push(itemData);