Skip to content

Commit

Permalink
feat: Excel exporter will now observe if numeric type has dollar form…
Browse files Browse the repository at this point in the history
…atter. If it does, it will use the dollarFormatter stylesheet.
  • Loading branch information
austinsimpson committed Dec 10, 2022
1 parent f730cee commit 076864a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/excel-export/src/excelExport.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
ExternalResource,
FileType,
FieldType,
Formatter,
Formatters,
GridOption,
KeyTitlePair,
Locale,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 076864a

Please sign in to comment.