@slickgrid-universal/excel-export 5.0.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/excelExport.service.js +20 -20
- package/dist/cjs/excelExport.service.js.map +1 -1
- package/dist/cjs/excelUtils.js +36 -32
- package/dist/cjs/excelUtils.js.map +1 -1
- package/dist/esm/excelExport.service.js +20 -20
- package/dist/esm/excelExport.service.js.map +1 -1
- package/dist/esm/excelUtils.js +29 -25
- package/dist/esm/excelUtils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/excelExport.service.d.ts +6 -17
- package/dist/types/excelExport.service.d.ts.map +1 -1
- package/dist/types/excelUtils.d.ts +16 -13
- package/dist/types/excelUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/excelExport.service.ts +29 -29
- package/src/excelUtils.ts +48 -28
|
@@ -19,14 +19,14 @@ export declare class ExcelExportService implements ExternalResource, BaseExcelEx
|
|
|
19
19
|
protected _workbook: Workbook;
|
|
20
20
|
protected _regularCellExcelFormats: {
|
|
21
21
|
[fieldId: string]: {
|
|
22
|
-
|
|
22
|
+
excelFormatId?: number;
|
|
23
23
|
getDataValueParser: GetDataValueCallback;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
protected _groupTotalExcelFormats: {
|
|
27
27
|
[fieldId: string]: {
|
|
28
28
|
groupType: string;
|
|
29
|
-
|
|
29
|
+
excelFormat?: ExcelFormatter;
|
|
30
30
|
getGroupTotalParser?: GetGroupTotalValueCallback;
|
|
31
31
|
};
|
|
32
32
|
};
|
|
@@ -39,19 +39,8 @@ export declare class ExcelExportService implements ExternalResource, BaseExcelEx
|
|
|
39
39
|
protected get _gridOptions(): GridOption;
|
|
40
40
|
get stylesheet(): StyleSheet;
|
|
41
41
|
get stylesheetFormats(): any;
|
|
42
|
-
get groupTotalExcelFormats():
|
|
43
|
-
|
|
44
|
-
groupType: string;
|
|
45
|
-
stylesheetFormatter?: ExcelFormatter | undefined;
|
|
46
|
-
getGroupTotalParser?: GetGroupTotalValueCallback | undefined;
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
get regularCellExcelFormats(): {
|
|
50
|
-
[fieldId: string]: {
|
|
51
|
-
stylesheetFormatterId?: number | undefined;
|
|
52
|
-
getDataValueParser: GetDataValueCallback;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
42
|
+
get groupTotalExcelFormats(): any;
|
|
43
|
+
get regularCellExcelFormats(): any;
|
|
55
44
|
dispose(): void;
|
|
56
45
|
/**
|
|
57
46
|
* Initialize the Export Service
|
|
@@ -111,7 +100,7 @@ export declare class ExcelExportService implements ExternalResource, BaseExcelEx
|
|
|
111
100
|
* @param {Number} row - row index
|
|
112
101
|
* @param {Object} itemObj - item datacontext object
|
|
113
102
|
*/
|
|
114
|
-
protected readRegularRowData(columns: Column[], row: number, itemObj: any): string[];
|
|
103
|
+
protected readRegularRowData(columns: Column[], row: number, itemObj: any, dataRowIdx: number): string[];
|
|
115
104
|
/**
|
|
116
105
|
* Get the grouped title(s) and its group title formatter, for example if we grouped by salesRep, the returned result would be:: 'Sales Rep: John Dow (2 items)'
|
|
117
106
|
* @param itemObj
|
|
@@ -122,6 +111,6 @@ export declare class ExcelExportService implements ExternalResource, BaseExcelEx
|
|
|
122
111
|
* For example if we grouped by "salesRep" and we have a Sum Aggregator on "sales", then the returned output would be:: ["Sum 123$"]
|
|
123
112
|
* @param itemObj
|
|
124
113
|
*/
|
|
125
|
-
protected readGroupedTotalRows(columns: Column[], itemObj: any): Array<ExcelColumnMetadata | string | number>;
|
|
114
|
+
protected readGroupedTotalRows(columns: Column[], itemObj: any, dataRowIdx: number): Array<ExcelColumnMetadata | string | number>;
|
|
126
115
|
}
|
|
127
116
|
//# sourceMappingURL=excelExport.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"excelExport.service.d.ts","sourceRoot":"","sources":["../../src/excelExport.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,QAAQ,EACR,KAAK,SAAS,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,MAAM,EACN,gBAAgB,EAChB,kBAAkB,IAAI,sBAAsB,EAC5C,iBAAiB,
|
|
1
|
+
{"version":3,"file":"excelExport.service.d.ts","sourceRoot":"","sources":["../../src/excelExport.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,QAAQ,EACR,KAAK,SAAS,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,MAAM,EACN,gBAAgB,EAChB,kBAAkB,IAAI,sBAAsB,EAC5C,iBAAiB,EAEjB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,UAAU,EACV,YAAY,EACZ,MAAM,EACN,aAAa,EACb,aAAa,EACb,SAAS,EACT,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAKL,QAAQ,EAIT,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,KAAK,cAAc,EAIpB,MAAM,cAAc,CAAC;AAOtB,qBAAa,kBAAmB,YAAW,gBAAgB,EAAE,sBAAsB;IACjF,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAiB;IAChD,SAAS,CAAC,KAAK,EAAG,SAAS,CAAC;IAC5B,SAAS,CAAC,QAAQ,EAAG,MAAM,CAAC;IAC5B,SAAS,CAAC,qBAAqB,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IACtD,SAAS,CAAC,cAAc,EAAE,KAAK,CAAC,YAAY,CAAC,CAAM;IACnD,SAAS,CAAC,wBAAwB,UAAS;IAC3C,SAAS,CAAC,gBAAgB,UAAS;IACnC,SAAS,CAAC,mBAAmB,EAAG,iBAAiB,CAAC;IAClD,SAAS,CAAC,MAAM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OAIG;IACH,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK,CAAC,mBAAmB,GAAG,MAAM,GAAG,MAAM,CAAC;CAqDlI"}
|
|
@@ -8,26 +8,29 @@ export declare const getExcelNumberCallback: GetDataValueCallback;
|
|
|
8
8
|
/** Parse a number which the user might have provided formatter options (for example a user might have provided { decimalSeparator: ',', thousandSeparator: ' '}) */
|
|
9
9
|
export declare function parseNumberWithFormatterOptions(value: any, column: Column, gridOptions: GridOption): any;
|
|
10
10
|
/** use different Excel Stylesheet Format as per the Field Type */
|
|
11
|
-
export declare function useCellFormatByFieldType(stylesheet: StyleSheet,
|
|
12
|
-
|
|
11
|
+
export declare function useCellFormatByFieldType(stylesheet: StyleSheet, excelFormats: any, columnDef: Column, grid: SlickGrid, autoDetect?: boolean): {
|
|
12
|
+
excelFormatId: number | undefined;
|
|
13
13
|
getDataValueParser: GetDataValueCallback;
|
|
14
14
|
};
|
|
15
|
-
export declare function getGroupTotalValue(totals: any,
|
|
15
|
+
export declare function getGroupTotalValue(totals: any, args: {
|
|
16
|
+
columnDef: Column;
|
|
17
|
+
groupType: string;
|
|
18
|
+
}): any;
|
|
16
19
|
/** Get numeric formatter options when defined or use default values (minDecimal, maxDecimal, thousandSeparator, decimalSeparator, wrapNegativeNumber) */
|
|
17
20
|
export declare function getNumericFormatterOptions(columnDef: Column, grid: SlickGrid, formatterType: FormatterType): {
|
|
18
|
-
minDecimal:
|
|
19
|
-
maxDecimal:
|
|
20
|
-
decimalSeparator:
|
|
21
|
-
thousandSeparator:
|
|
22
|
-
wrapNegativeNumber:
|
|
23
|
-
currencyPrefix:
|
|
24
|
-
currencySuffix:
|
|
21
|
+
minDecimal: number;
|
|
22
|
+
maxDecimal: number;
|
|
23
|
+
decimalSeparator: '.' | ',';
|
|
24
|
+
thousandSeparator: '' | '.' | ',' | '_' | ' ';
|
|
25
|
+
wrapNegativeNumber: boolean;
|
|
26
|
+
currencyPrefix: string;
|
|
27
|
+
currencySuffix: string;
|
|
25
28
|
numberPrefix: string;
|
|
26
29
|
numberSuffix: string;
|
|
27
30
|
};
|
|
28
|
-
export declare function getFormatterNumericDataType(formatter?: Formatter):
|
|
29
|
-
export declare function getExcelFormatFromGridFormatter(stylesheet: StyleSheet,
|
|
30
|
-
|
|
31
|
+
export declare function getFormatterNumericDataType(formatter?: Formatter): 'currency' | 'decimal' | 'percent';
|
|
32
|
+
export declare function getExcelFormatFromGridFormatter(stylesheet: StyleSheet, excelFormats: any, columnDef: Column, grid: SlickGrid, formatterType: FormatterType): {
|
|
33
|
+
excelFormat: ExcelFormatter;
|
|
31
34
|
groupType: string;
|
|
32
35
|
};
|
|
33
36
|
//# sourceMappingURL=excelUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"excelUtils.d.ts","sourceRoot":"","sources":["../../src/excelUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,UAAU,EACV,SAAS,EACV,MAAM,6BAA6B,CAAC;AAYrC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;CAAE,CAAC;AAGtD,eAAO,MAAM,6BAA6B,EAAE,
|
|
1
|
+
{"version":3,"file":"excelUtils.d.ts","sourceRoot":"","sources":["../../src/excelUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,UAAU,EACV,SAAS,EACV,MAAM,6BAA6B,CAAC;AAYrC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;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U,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,GAAG;IAC5J,WAAW,EAAE,cAAc,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB,CAkFA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slickgrid-universal/excel-export",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Excel Export (xls/xlsx) Service.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"not dead"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@slickgrid-universal/common": "~5.0
|
|
42
|
-
"@slickgrid-universal/utils": "~5.
|
|
41
|
+
"@slickgrid-universal/common": "~5.2.0",
|
|
42
|
+
"@slickgrid-universal/utils": "~5.2.0",
|
|
43
43
|
"excel-builder-vanilla": "^3.0.1"
|
|
44
44
|
},
|
|
45
45
|
"funding": {
|
|
46
46
|
"type": "ko_fi",
|
|
47
47
|
"url": "https://ko-fi.com/ghiscoding"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "d7de27ab3ac3c7e2d48302603ac76aaf794e66a2"
|
|
50
50
|
}
|
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
ContainerService,
|
|
12
12
|
ExcelExportService as BaseExcelExportService,
|
|
13
13
|
ExcelExportOption,
|
|
14
|
+
ExcelGroupValueParserArgs,
|
|
14
15
|
ExternalResource,
|
|
15
|
-
|
|
16
16
|
GetDataValueCallback,
|
|
17
17
|
GetGroupTotalValueCallback,
|
|
18
18
|
GridOption,
|
|
@@ -48,7 +48,7 @@ const DEFAULT_EXPORT_OPTIONS: ExcelExportOption = {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
export class ExcelExportService implements ExternalResource, BaseExcelExportService {
|
|
51
|
-
protected _fileFormat = FileType.xlsx;
|
|
51
|
+
protected _fileFormat: FileType = FileType.xlsx;
|
|
52
52
|
protected _grid!: SlickGrid;
|
|
53
53
|
protected _locales!: Locale;
|
|
54
54
|
protected _groupedColumnHeaders?: Array<KeyTitlePair>;
|
|
@@ -64,8 +64,8 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
64
64
|
protected _workbook!: Workbook;
|
|
65
65
|
|
|
66
66
|
// references of each detected cell and/or group total formats
|
|
67
|
-
protected _regularCellExcelFormats: { [fieldId: string]: {
|
|
68
|
-
protected _groupTotalExcelFormats: { [fieldId: string]: { groupType: string;
|
|
67
|
+
protected _regularCellExcelFormats: { [fieldId: string]: { excelFormatId?: number; getDataValueParser: GetDataValueCallback; }; } = {};
|
|
68
|
+
protected _groupTotalExcelFormats: { [fieldId: string]: { groupType: string; excelFormat?: ExcelFormatter; getGroupTotalParser?: GetGroupTotalValueCallback; }; } = {};
|
|
69
69
|
|
|
70
70
|
/** ExcelExportService class name which is use to find service instance in the external registered services */
|
|
71
71
|
readonly className = 'ExcelExportService';
|
|
@@ -84,23 +84,23 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
84
84
|
return this._grid?.getOptions() || {} as GridOption;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
get stylesheet() {
|
|
87
|
+
get stylesheet(): StyleSheet {
|
|
88
88
|
return this._stylesheet;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
get stylesheetFormats() {
|
|
91
|
+
get stylesheetFormats(): any {
|
|
92
92
|
return this._stylesheetFormats;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
get groupTotalExcelFormats() {
|
|
95
|
+
get groupTotalExcelFormats(): any {
|
|
96
96
|
return this._groupTotalExcelFormats;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
get regularCellExcelFormats() {
|
|
99
|
+
get regularCellExcelFormats(): any {
|
|
100
100
|
return this._regularCellExcelFormats;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
dispose() {
|
|
103
|
+
dispose(): void {
|
|
104
104
|
this._pubSubService?.unsubscribeAll();
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -155,15 +155,15 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
155
155
|
this._stylesheet = this._workbook.getStyleSheet();
|
|
156
156
|
|
|
157
157
|
// create some common default Excel formatters that will be used
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
const
|
|
158
|
+
const boldFormat = this._stylesheet.createFormat({ font: { bold: true } });
|
|
159
|
+
const stringFormat = this._stylesheet.createFormat({ format: '@' });
|
|
160
|
+
const numberFormat = this._stylesheet.createFormat({ format: '0' });
|
|
161
161
|
this._stylesheetFormats = {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
boldFormat,
|
|
163
|
+
numberFormat,
|
|
164
|
+
stringFormat,
|
|
165
165
|
};
|
|
166
|
-
this._sheet.setColumnFormats([
|
|
166
|
+
this._sheet.setColumnFormats([boldFormat]);
|
|
167
167
|
|
|
168
168
|
// get the CSV output from the grid data
|
|
169
169
|
const dataOutput = this.getDataOutput();
|
|
@@ -238,7 +238,7 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
238
238
|
const outputData: Array<string[] | ExcelColumnMetadata[]> = [];
|
|
239
239
|
const gridExportOptions = this._gridOptions?.excelExportOptions;
|
|
240
240
|
const columnHeaderStyle = gridExportOptions?.columnHeaderStyle;
|
|
241
|
-
let columnHeaderStyleId = this._stylesheetFormats.
|
|
241
|
+
let columnHeaderStyleId = this._stylesheetFormats.boldFormat.id;
|
|
242
242
|
if (columnHeaderStyle) {
|
|
243
243
|
columnHeaderStyleId = this._stylesheet.createFormat(columnHeaderStyle).id;
|
|
244
244
|
}
|
|
@@ -435,13 +435,13 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
435
435
|
// Normal row (not grouped by anything) would have an ID which was predefined in the Grid Columns definition
|
|
436
436
|
if (itemObj[this._datasetIdPropName] !== null && itemObj[this._datasetIdPropName] !== undefined) {
|
|
437
437
|
// get regular row item data
|
|
438
|
-
originalDaraArray.push(this.readRegularRowData(columns, rowNumber, itemObj));
|
|
438
|
+
originalDaraArray.push(this.readRegularRowData(columns, rowNumber, itemObj, rowNumber));
|
|
439
439
|
} else if (this._hasGroupedItems && itemObj.__groupTotals === undefined) {
|
|
440
440
|
// get the group row
|
|
441
441
|
originalDaraArray.push([this.readGroupedRowTitle(itemObj)]);
|
|
442
442
|
} else if (itemObj.__groupTotals) {
|
|
443
443
|
// else if the row is a Group By and we have agreggators, then a property of '__groupTotals' would exist under that object
|
|
444
|
-
originalDaraArray.push(this.readGroupedTotalRows(columns, itemObj));
|
|
444
|
+
originalDaraArray.push(this.readGroupedTotalRows(columns, itemObj, rowNumber));
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
447
|
}
|
|
@@ -454,7 +454,7 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
454
454
|
* @param {Number} row - row index
|
|
455
455
|
* @param {Object} itemObj - item datacontext object
|
|
456
456
|
*/
|
|
457
|
-
protected readRegularRowData(columns: Column[], row: number, itemObj: any): string[] {
|
|
457
|
+
protected readRegularRowData(columns: Column[], row: number, itemObj: any, dataRowIdx: number): string[] {
|
|
458
458
|
let idx = 0;
|
|
459
459
|
const rowOutputStrings = [];
|
|
460
460
|
const columnsLn = columns.length;
|
|
@@ -539,7 +539,7 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
539
539
|
const cellStyleFormat = useCellFormatByFieldType(this._stylesheet, this._stylesheetFormats, columnDef, this._grid, autoDetectCellFormat);
|
|
540
540
|
// user could also override style and/or valueParserCallback
|
|
541
541
|
if (columnDef.excelExportOptions?.style) {
|
|
542
|
-
cellStyleFormat.
|
|
542
|
+
cellStyleFormat.excelFormatId = this._stylesheet.createFormat(columnDef.excelExportOptions.style).id;
|
|
543
543
|
}
|
|
544
544
|
if (columnDef.excelExportOptions?.valueParserCallback) {
|
|
545
545
|
cellStyleFormat.getDataValueParser = columnDef.excelExportOptions.valueParserCallback;
|
|
@@ -552,8 +552,8 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
552
552
|
itemData = stripTags(itemData as string);
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
-
const {
|
|
556
|
-
itemData = getDataValueParser(itemData, columnDef,
|
|
555
|
+
const { excelFormatId, getDataValueParser } = this._regularCellExcelFormats[columnDef.id];
|
|
556
|
+
itemData = getDataValueParser(itemData, { columnDef, excelFormatId, stylesheet: this._stylesheet, gridOptions: this._gridOptions, dataRowIdx, dataContext: itemObj });
|
|
557
557
|
|
|
558
558
|
rowOutputStrings.push(itemData);
|
|
559
559
|
idx++;
|
|
@@ -584,7 +584,7 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
584
584
|
* For example if we grouped by "salesRep" and we have a Sum Aggregator on "sales", then the returned output would be:: ["Sum 123$"]
|
|
585
585
|
* @param itemObj
|
|
586
586
|
*/
|
|
587
|
-
protected readGroupedTotalRows(columns: Column[], itemObj: any): Array<ExcelColumnMetadata | string | number> {
|
|
587
|
+
protected readGroupedTotalRows(columns: Column[], itemObj: any, dataRowIdx: number): Array<ExcelColumnMetadata | string | number> {
|
|
588
588
|
const groupingAggregatorRowText = this._excelExportOptions.groupingAggregatorRowText || '';
|
|
589
589
|
const outputStrings: Array<ExcelColumnMetadata | string | number> = [groupingAggregatorRowText];
|
|
590
590
|
|
|
@@ -607,17 +607,17 @@ export class ExcelExportService implements ExternalResource, BaseExcelExportServ
|
|
|
607
607
|
if (!groupCellFormat?.groupType) {
|
|
608
608
|
groupCellFormat = getExcelFormatFromGridFormatter(this._stylesheet, this._stylesheetFormats, columnDef, this._grid, 'group');
|
|
609
609
|
if (columnDef.groupTotalsExcelExportOptions?.style) {
|
|
610
|
-
groupCellFormat.
|
|
610
|
+
groupCellFormat.excelFormat = this._stylesheet.createFormat(columnDef.groupTotalsExcelExportOptions.style);
|
|
611
611
|
}
|
|
612
612
|
this._groupTotalExcelFormats[columnDef.id] = groupCellFormat;
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
const groupTotalParser = columnDef.groupTotalsExcelExportOptions?.valueParserCallback ?? getGroupTotalValue;
|
|
616
616
|
if (itemObj[groupCellFormat.groupType]?.[columnDef.field] !== undefined) {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
617
|
+
const groupData = groupTotalParser(itemObj, { columnDef, groupType: groupCellFormat.groupType, excelFormatId: groupCellFormat.excelFormat?.id, stylesheet: this._stylesheet, dataRowIdx } as ExcelGroupValueParserArgs);
|
|
618
|
+
itemData = (typeof groupData === 'object' && groupData.hasOwnProperty('metadata'))
|
|
619
|
+
? groupData
|
|
620
|
+
: itemData = { value: groupData, metadata: { style: groupCellFormat.excelFormat?.id } };
|
|
621
621
|
}
|
|
622
622
|
} else if (columnDef.groupTotalsFormatter) {
|
|
623
623
|
const totalResult = columnDef.groupTotalsFormatter(itemObj, columnDef, this._grid);
|
package/src/excelUtils.ts
CHANGED
|
@@ -21,14 +21,18 @@ import { stripTags } from '@slickgrid-universal/utils';
|
|
|
21
21
|
export type ExcelFormatter = object & { id: number; };
|
|
22
22
|
|
|
23
23
|
// define all type of potential excel data function callbacks
|
|
24
|
-
export const getExcelSameInputDataCallback: GetDataValueCallback = (data) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
export const getExcelSameInputDataCallback: GetDataValueCallback = (data, { excelFormatId }) => {
|
|
25
|
+
return excelFormatId !== undefined
|
|
26
|
+
? { value: data, metadata: { style: excelFormatId } }
|
|
27
|
+
: data;
|
|
28
|
+
};
|
|
29
|
+
export const getExcelNumberCallback: GetDataValueCallback = (data, { columnDef, excelFormatId, gridOptions }) => ({
|
|
30
|
+
value: typeof data === 'string' && /\d/g.test(data) ? parseNumberWithFormatterOptions(data, columnDef, gridOptions) : data,
|
|
31
|
+
metadata: { style: excelFormatId }
|
|
28
32
|
});
|
|
29
33
|
|
|
30
34
|
/** Parse a number which the user might have provided formatter options (for example a user might have provided { decimalSeparator: ',', thousandSeparator: ' '}) */
|
|
31
|
-
export function parseNumberWithFormatterOptions(value: any, column: Column, gridOptions: GridOption) {
|
|
35
|
+
export function parseNumberWithFormatterOptions(value: any, column: Column, gridOptions: GridOption): any {
|
|
32
36
|
let outValue = value;
|
|
33
37
|
if (typeof value === 'string' && value) {
|
|
34
38
|
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', column, gridOptions, Constants.DEFAULT_NUMBER_DECIMAL_SEPARATOR);
|
|
@@ -41,24 +45,37 @@ export function parseNumberWithFormatterOptions(value: any, column: Column, grid
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
/** use different Excel Stylesheet Format as per the Field Type */
|
|
44
|
-
export function useCellFormatByFieldType(stylesheet: StyleSheet,
|
|
48
|
+
export function useCellFormatByFieldType(stylesheet: StyleSheet, excelFormats: any, columnDef: Column, grid: SlickGrid, autoDetect = true): {
|
|
49
|
+
excelFormatId: number | undefined;
|
|
50
|
+
getDataValueParser: GetDataValueCallback;
|
|
51
|
+
} {
|
|
45
52
|
const fieldType = getColumnFieldType(columnDef);
|
|
46
|
-
let
|
|
53
|
+
let excelFormatId: number | undefined;
|
|
47
54
|
let callback: GetDataValueCallback = getExcelSameInputDataCallback;
|
|
48
55
|
|
|
49
56
|
if (fieldType === FieldType.number && autoDetect) {
|
|
50
|
-
|
|
57
|
+
excelFormatId = getExcelFormatFromGridFormatter(stylesheet, excelFormats, columnDef, grid, 'cell').excelFormat.id;
|
|
51
58
|
callback = getExcelNumberCallback;
|
|
52
59
|
}
|
|
53
|
-
return {
|
|
60
|
+
return { excelFormatId, getDataValueParser: callback };
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
export function getGroupTotalValue(totals: any, columnDef: Column, groupType: string) {
|
|
57
|
-
return totals?.[groupType]?.[columnDef.field] ?? 0;
|
|
63
|
+
export function getGroupTotalValue(totals: any, args: { columnDef: Column, groupType: string; }): any {
|
|
64
|
+
return totals?.[args.groupType]?.[args.columnDef.field] ?? 0;
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
/** Get numeric formatter options when defined or use default values (minDecimal, maxDecimal, thousandSeparator, decimalSeparator, wrapNegativeNumber) */
|
|
61
|
-
export function getNumericFormatterOptions(columnDef: Column, grid: SlickGrid, formatterType: FormatterType) {
|
|
68
|
+
export function getNumericFormatterOptions(columnDef: Column, grid: SlickGrid, formatterType: FormatterType): {
|
|
69
|
+
minDecimal: number;
|
|
70
|
+
maxDecimal: number;
|
|
71
|
+
decimalSeparator: '.' | ',';
|
|
72
|
+
thousandSeparator: '' | '.' | ',' | '_' | ' ';
|
|
73
|
+
wrapNegativeNumber: boolean;
|
|
74
|
+
currencyPrefix: string;
|
|
75
|
+
currencySuffix: string;
|
|
76
|
+
numberPrefix: string;
|
|
77
|
+
numberSuffix: string;
|
|
78
|
+
} {
|
|
62
79
|
let dataType: 'currency' | 'decimal' | 'percent' | 'regular';
|
|
63
80
|
|
|
64
81
|
if (formatterType === 'group') {
|
|
@@ -105,7 +122,7 @@ export function getNumericFormatterOptions(columnDef: Column, grid: SlickGrid, f
|
|
|
105
122
|
return retrieveFormatterOptions(columnDef, grid, dataType!, formatterType);
|
|
106
123
|
}
|
|
107
124
|
|
|
108
|
-
export function getFormatterNumericDataType(formatter?: Formatter) {
|
|
125
|
+
export function getFormatterNumericDataType(formatter?: Formatter): 'currency' | 'decimal' | 'percent' {
|
|
109
126
|
let dataType: 'currency' | 'decimal' | 'percent' | 'regular';
|
|
110
127
|
|
|
111
128
|
switch (formatter) {
|
|
@@ -131,10 +148,13 @@ export function getFormatterNumericDataType(formatter?: Formatter) {
|
|
|
131
148
|
return dataType;
|
|
132
149
|
}
|
|
133
150
|
|
|
134
|
-
export function getExcelFormatFromGridFormatter(stylesheet: StyleSheet,
|
|
151
|
+
export function getExcelFormatFromGridFormatter(stylesheet: StyleSheet, excelFormats: any, columnDef: Column, grid: SlickGrid, formatterType: FormatterType): {
|
|
152
|
+
excelFormat: ExcelFormatter;
|
|
153
|
+
groupType: string;
|
|
154
|
+
} {
|
|
135
155
|
let format = '';
|
|
136
|
-
let groupType = '';
|
|
137
|
-
let
|
|
156
|
+
let groupType = columnDef.groupTotalsExcelExportOptions?.groupType || '';
|
|
157
|
+
let excelFormat: undefined | ExcelFormatter;
|
|
138
158
|
const fieldType = getColumnFieldType(columnDef);
|
|
139
159
|
|
|
140
160
|
if (formatterType === 'group') {
|
|
@@ -163,7 +183,7 @@ export function getExcelFormatFromGridFormatter(stylesheet: StyleSheet, styleshe
|
|
|
163
183
|
groupType = 'sum';
|
|
164
184
|
break;
|
|
165
185
|
default:
|
|
166
|
-
|
|
186
|
+
excelFormat = excelFormats.numberFormat;
|
|
167
187
|
break;
|
|
168
188
|
}
|
|
169
189
|
} else {
|
|
@@ -174,15 +194,15 @@ export function getExcelFormatFromGridFormatter(stylesheet: StyleSheet, styleshe
|
|
|
174
194
|
// when formatter is a Formatter.multiple, we need to loop through each of its formatter to find the best possible Excel format
|
|
175
195
|
if (Array.isArray(columnDef.params?.formatters)) {
|
|
176
196
|
for (const formatter of columnDef.params.formatters) {
|
|
177
|
-
const {
|
|
178
|
-
if (
|
|
179
|
-
|
|
197
|
+
const { excelFormat: excelFormatResult } = getExcelFormatFromGridFormatter(stylesheet, excelFormats, { ...columnDef, formatter } as Column, grid, formatterType);
|
|
198
|
+
if (excelFormatResult !== excelFormats.numberFormat) {
|
|
199
|
+
excelFormat = excelFormatResult;
|
|
180
200
|
break;
|
|
181
201
|
}
|
|
182
202
|
}
|
|
183
203
|
}
|
|
184
|
-
if (!
|
|
185
|
-
|
|
204
|
+
if (!excelFormat) {
|
|
205
|
+
excelFormat = excelFormats.numberFormat;
|
|
186
206
|
}
|
|
187
207
|
break;
|
|
188
208
|
case Formatters.currency:
|
|
@@ -198,21 +218,21 @@ export function getExcelFormatFromGridFormatter(stylesheet: StyleSheet, styleshe
|
|
|
198
218
|
format = createExcelFormatFromGridFormatter(columnDef, grid, 'cell');
|
|
199
219
|
break;
|
|
200
220
|
default:
|
|
201
|
-
|
|
221
|
+
excelFormat = excelFormats.numberFormat;
|
|
202
222
|
break;
|
|
203
223
|
}
|
|
204
224
|
break;
|
|
205
225
|
}
|
|
206
226
|
}
|
|
207
227
|
|
|
208
|
-
if (!
|
|
228
|
+
if (!excelFormat && (columnDef.formatter || columnDef.groupTotalsFormatter)) {
|
|
209
229
|
format = createExcelFormatFromGridFormatter(columnDef, grid, formatterType, groupType);
|
|
210
|
-
if (!
|
|
211
|
-
|
|
230
|
+
if (!excelFormats.hasOwnProperty(format)) {
|
|
231
|
+
excelFormats[format] = stylesheet.createFormat({ format }); // save new formatter with its format as a prop key
|
|
212
232
|
}
|
|
213
|
-
|
|
233
|
+
excelFormat = excelFormats[format] as ExcelFormatter;
|
|
214
234
|
}
|
|
215
|
-
return {
|
|
235
|
+
return { excelFormat: excelFormat as ExcelFormatter, groupType };
|
|
216
236
|
}
|
|
217
237
|
|
|
218
238
|
// --
|