Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Excel exporter will now observe if numeric type has dollar form… #843

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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