@slickgrid-universal/excel-export 2.5.0 → 2.6.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.
Files changed (37) hide show
  1. package/dist/commonjs/excelExport.service.js +572 -572
  2. package/dist/commonjs/excelUtils.js +258 -258
  3. package/dist/commonjs/index.js +5 -5
  4. package/dist/commonjs/interfaces/excelCellFormat.interface.js +2 -2
  5. package/dist/commonjs/interfaces/excelMetadata.interface.js +2 -2
  6. package/dist/commonjs/interfaces/excelStylesheet.interface.js +2 -2
  7. package/dist/commonjs/interfaces/index.js +19 -19
  8. package/dist/esm/excelExport.service.js +570 -570
  9. package/dist/esm/excelUtils.js +247 -247
  10. package/dist/esm/index.js +1 -1
  11. package/dist/esm/interfaces/excelCellFormat.interface.js +1 -1
  12. package/dist/esm/interfaces/excelMetadata.interface.js +1 -1
  13. package/dist/esm/interfaces/excelStylesheet.interface.js +1 -1
  14. package/dist/esm/interfaces/index.js +3 -3
  15. package/dist/tsconfig.tsbuildinfo +1 -0
  16. package/dist/{commonjs → types}/excelExport.service.d.ts +137 -136
  17. package/dist/types/excelExport.service.d.ts.map +1 -0
  18. package/dist/{esm → types}/excelUtils.d.ts +32 -31
  19. package/dist/types/excelUtils.d.ts.map +1 -0
  20. package/dist/{esm → types}/index.d.ts +2 -1
  21. package/dist/types/index.d.ts.map +1 -0
  22. package/dist/{esm → types}/interfaces/excelCellFormat.interface.d.ts +6 -5
  23. package/dist/types/interfaces/excelCellFormat.interface.d.ts.map +1 -0
  24. package/dist/{commonjs → types}/interfaces/excelMetadata.interface.d.ts +10 -9
  25. package/dist/types/interfaces/excelMetadata.interface.d.ts.map +1 -0
  26. package/dist/{commonjs → types}/interfaces/excelStylesheet.interface.d.ts +34 -33
  27. package/dist/types/interfaces/excelStylesheet.interface.d.ts.map +1 -0
  28. package/dist/{commonjs → types}/interfaces/index.d.ts +4 -3
  29. package/dist/types/interfaces/index.d.ts.map +1 -0
  30. package/package.json +8 -8
  31. package/dist/commonjs/excelUtils.d.ts +0 -31
  32. package/dist/commonjs/index.d.ts +0 -1
  33. package/dist/commonjs/interfaces/excelCellFormat.interface.d.ts +0 -5
  34. package/dist/esm/excelExport.service.d.ts +0 -136
  35. package/dist/esm/interfaces/excelMetadata.interface.d.ts +0 -9
  36. package/dist/esm/interfaces/excelStylesheet.interface.d.ts +0 -33
  37. package/dist/esm/interfaces/index.d.ts +0 -3
@@ -1,259 +1,259 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExcelFormatFromGridFormatter = exports.getFormatterNumericDataType = exports.getNumericFormatterOptions = exports.getGroupTotalValue = exports.useCellFormatByFieldType = exports.parseNumberWithFormatterOptions = exports.getExcelNumberCallback = exports.getExcelSameInputDataCallback = void 0;
4
- const common_1 = require("@slickgrid-universal/common");
5
- // define all type of potential excel data function callbacks
6
- const getExcelSameInputDataCallback = (data) => data;
7
- exports.getExcelSameInputDataCallback = getExcelSameInputDataCallback;
8
- const getExcelNumberCallback = (data, column, excelFormatterId, _excelSheet, gridOptions) => ({
9
- value: typeof data === 'string' && /\d/g.test(data) ? parseNumberWithFormatterOptions(data, column, gridOptions) : data,
10
- metadata: { style: excelFormatterId }
11
- });
12
- exports.getExcelNumberCallback = getExcelNumberCallback;
13
- /** Parse a number which the user might have provided formatter options (for example a user might have provided { decimalSeparator: ',', thousandSeparator: ' '}) */
14
- function parseNumberWithFormatterOptions(value, column, gridOptions) {
15
- let outValue = value;
16
- if (typeof value === 'string' && value) {
17
- const decimalSeparator = (0, common_1.getValueFromParamsOrFormatterOptions)('decimalSeparator', column, gridOptions, common_1.Constants.DEFAULT_NUMBER_DECIMAL_SEPARATOR);
18
- const val = (decimalSeparator === ',')
19
- ? parseFloat(value.replace(/[^0-9\,]+/g, '').replace(',', '.'))
20
- : parseFloat(value.replace(/[^\d\.]/g, ''));
21
- outValue = isNaN(val) ? value : val;
22
- }
23
- return outValue;
24
- }
25
- exports.parseNumberWithFormatterOptions = parseNumberWithFormatterOptions;
26
- /** use different Excel Stylesheet Format as per the Field Type */
27
- function useCellFormatByFieldType(stylesheet, stylesheetFormatters, columnDef, grid) {
28
- const fieldType = (0, common_1.getColumnFieldType)(columnDef);
29
- let stylesheetFormatterId;
30
- let callback = exports.getExcelSameInputDataCallback;
31
- if (fieldType === common_1.FieldType.number) {
32
- stylesheetFormatterId = getExcelFormatFromGridFormatter(stylesheet, stylesheetFormatters, columnDef, grid, 'cell').stylesheetFormatter.id;
33
- callback = exports.getExcelNumberCallback;
34
- }
35
- return { stylesheetFormatterId, getDataValueParser: callback };
36
- }
37
- exports.useCellFormatByFieldType = useCellFormatByFieldType;
38
- function getGroupTotalValue(totals, columnDef, groupType) {
39
- var _a, _b;
40
- return (_b = (_a = totals === null || totals === void 0 ? void 0 : totals[groupType]) === null || _a === void 0 ? void 0 : _a[columnDef.field]) !== null && _b !== void 0 ? _b : 0;
41
- }
42
- exports.getGroupTotalValue = getGroupTotalValue;
43
- /** Get numeric formatter options when defined or use default values (minDecimal, maxDecimal, thousandSeparator, decimalSeparator, wrapNegativeNumber) */
44
- function getNumericFormatterOptions(columnDef, grid, formatterType) {
45
- var _a;
46
- let dataType;
47
- if (formatterType === 'group') {
48
- switch (columnDef.groupTotalsFormatter) {
49
- case common_1.GroupTotalFormatters.avgTotalsCurrency:
50
- case common_1.GroupTotalFormatters.avgTotalsDollar:
51
- case common_1.GroupTotalFormatters.sumTotalsCurrency:
52
- case common_1.GroupTotalFormatters.sumTotalsCurrencyColored:
53
- case common_1.GroupTotalFormatters.sumTotalsDollar:
54
- case common_1.GroupTotalFormatters.sumTotalsDollarBold:
55
- case common_1.GroupTotalFormatters.sumTotalsDollarColored:
56
- case common_1.GroupTotalFormatters.sumTotalsDollarColoredBold:
57
- dataType = 'currency';
58
- break;
59
- case common_1.GroupTotalFormatters.avgTotalsPercentage:
60
- dataType = 'percent';
61
- break;
62
- case common_1.GroupTotalFormatters.avgTotals:
63
- case common_1.GroupTotalFormatters.minTotals:
64
- case common_1.GroupTotalFormatters.maxTotals:
65
- case common_1.GroupTotalFormatters.sumTotals:
66
- case common_1.GroupTotalFormatters.sumTotalsColored:
67
- case common_1.GroupTotalFormatters.sumTotalsBold:
68
- default:
69
- // side note, formatters are using "regular" without any decimal limits (min, max),
70
- // however in Excel export with custom format that doesn't work so well, we should use "decimal" to at least show optional decimals with "##"
71
- dataType = 'decimal';
72
- break;
73
- }
74
- }
75
- else {
76
- // when formatter is a Formatter.multiple, we need to loop through each of its formatter to find the best numeric data type
77
- if (columnDef.formatter === common_1.Formatters.multiple && Array.isArray((_a = columnDef.params) === null || _a === void 0 ? void 0 : _a.formatters)) {
78
- dataType = 'decimal';
79
- for (const formatter of columnDef.params.formatters) {
80
- dataType = getFormatterNumericDataType(formatter);
81
- if (dataType !== 'decimal') {
82
- break; // if we found something different than the default (decimal) then we can assume that we found our type so we can stop & return
83
- }
84
- }
85
- }
86
- else {
87
- dataType = getFormatterNumericDataType(columnDef.formatter);
88
- }
89
- }
90
- return (0, common_1.retrieveFormatterOptions)(columnDef, grid, dataType, formatterType);
91
- }
92
- exports.getNumericFormatterOptions = getNumericFormatterOptions;
93
- function getFormatterNumericDataType(formatter) {
94
- let dataType;
95
- switch (formatter) {
96
- case common_1.Formatters.currency:
97
- case common_1.Formatters.dollar:
98
- case common_1.Formatters.dollarColored:
99
- case common_1.Formatters.dollarColoredBold:
100
- dataType = 'currency';
101
- break;
102
- case common_1.Formatters.percent:
103
- case common_1.Formatters.percentComplete:
104
- case common_1.Formatters.percentCompleteBar:
105
- case common_1.Formatters.percentCompleteBarWithText:
106
- case common_1.Formatters.percentSymbol:
107
- dataType = 'percent';
108
- break;
109
- case common_1.Formatters.decimal:
110
- default:
111
- // use "decimal" instead of "regular" to show optional decimals "##" in Excel
112
- dataType = 'decimal';
113
- break;
114
- }
115
- return dataType;
116
- }
117
- exports.getFormatterNumericDataType = getFormatterNumericDataType;
118
- function getExcelFormatFromGridFormatter(stylesheet, stylesheetFormatters, columnDef, grid, formatterType) {
119
- var _a;
120
- let format = '';
121
- let groupType = '';
122
- let stylesheetFormatter;
123
- const fieldType = (0, common_1.getColumnFieldType)(columnDef);
124
- if (formatterType === 'group') {
125
- switch (columnDef.groupTotalsFormatter) {
126
- case common_1.GroupTotalFormatters.avgTotals:
127
- case common_1.GroupTotalFormatters.avgTotalsCurrency:
128
- case common_1.GroupTotalFormatters.avgTotalsDollar:
129
- case common_1.GroupTotalFormatters.avgTotalsPercentage:
130
- groupType = 'avg';
131
- break;
132
- case common_1.GroupTotalFormatters.minTotals:
133
- groupType = 'min';
134
- break;
135
- case common_1.GroupTotalFormatters.maxTotals:
136
- groupType = 'max';
137
- break;
138
- case common_1.GroupTotalFormatters.sumTotals:
139
- case common_1.GroupTotalFormatters.sumTotalsBold:
140
- case common_1.GroupTotalFormatters.sumTotalsColored:
141
- case common_1.GroupTotalFormatters.sumTotalsCurrency:
142
- case common_1.GroupTotalFormatters.sumTotalsCurrencyColored:
143
- case common_1.GroupTotalFormatters.sumTotalsDollar:
144
- case common_1.GroupTotalFormatters.sumTotalsDollarColoredBold:
145
- case common_1.GroupTotalFormatters.sumTotalsDollarColored:
146
- case common_1.GroupTotalFormatters.sumTotalsDollarBold:
147
- groupType = 'sum';
148
- break;
149
- default:
150
- stylesheetFormatter = stylesheetFormatters.numberFormatter;
151
- break;
152
- }
153
- }
154
- else {
155
- switch (fieldType) {
156
- case common_1.FieldType.number:
157
- switch (columnDef.formatter) {
158
- case common_1.Formatters.multiple:
159
- // when formatter is a Formatter.multiple, we need to loop through each of its formatter to find the best possible Excel format
160
- if (Array.isArray((_a = columnDef.params) === null || _a === void 0 ? void 0 : _a.formatters)) {
161
- for (const formatter of columnDef.params.formatters) {
162
- const { stylesheetFormatter: stylesheetFormatterResult } = getExcelFormatFromGridFormatter(stylesheet, stylesheetFormatters, { ...columnDef, formatter }, grid, formatterType);
163
- if (stylesheetFormatterResult !== stylesheetFormatters.numberFormatter) {
164
- stylesheetFormatter = stylesheetFormatterResult;
165
- break;
166
- }
167
- }
168
- }
169
- if (!stylesheetFormatter) {
170
- stylesheetFormatter = stylesheetFormatters.numberFormatter;
171
- }
172
- break;
173
- case common_1.Formatters.currency:
174
- case common_1.Formatters.decimal:
175
- case common_1.Formatters.dollar:
176
- case common_1.Formatters.dollarColored:
177
- case common_1.Formatters.dollarColoredBold:
178
- case common_1.Formatters.percent:
179
- case common_1.Formatters.percentComplete:
180
- case common_1.Formatters.percentCompleteBar:
181
- case common_1.Formatters.percentCompleteBarWithText:
182
- case common_1.Formatters.percentSymbol:
183
- format = createExcelFormatFromGridFormatter(columnDef, grid, 'cell');
184
- break;
185
- default:
186
- stylesheetFormatter = stylesheetFormatters.numberFormatter;
187
- break;
188
- }
189
- break;
190
- }
191
- }
192
- if (!stylesheetFormatter && (columnDef.formatter || columnDef.groupTotalsFormatter)) {
193
- format = createExcelFormatFromGridFormatter(columnDef, grid, formatterType, groupType);
194
- if (!stylesheetFormatters.hasOwnProperty(format)) {
195
- stylesheetFormatters[format] = stylesheet.createFormat({ format }); // save new formatter with its format as a prop key
196
- }
197
- stylesheetFormatter = stylesheetFormatters[format];
198
- }
199
- return { stylesheetFormatter: stylesheetFormatter, groupType };
200
- }
201
- exports.getExcelFormatFromGridFormatter = getExcelFormatFromGridFormatter;
202
- // --
203
- // private functions
204
- // ------------------
205
- function createFormatFromNumber(formattedVal) {
206
- // full number syntax can have up to 7 sections, for example::
207
- // Total: ($10,420.55 USD) Expensed
208
- const [
209
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
210
- _, prefix, openBraquet, symbolPrefix, number, symbolSuffix, closingBraquet, suffix] = (formattedVal === null || formattedVal === void 0 ? void 0 : formattedVal.match(/^([^\d\(\-]*)([\(]?)([^\d]*)([\-]?[\w]]?[\d\s]*[.,\d]*[\d]*[^)\s\%]?)([^\d.,)]*)([\)]?)([^\d]*)$/i)) || [];
211
- // we use 1 so that they won't be removed when rounding numbers, however Excel uses 0 and # symbol
212
- // replace 1's by 0's (required numbers) and replace 2's by "#" (optional numbers)
213
- const replacedNumber = (number || '').replace(/1/g, '0').replace(/[2]/g, '#');
214
- const format = [
215
- escapeQuotes(prefix !== null && prefix !== void 0 ? prefix : ''),
216
- openBraquet !== null && openBraquet !== void 0 ? openBraquet : '',
217
- escapeQuotes(symbolPrefix !== null && symbolPrefix !== void 0 ? symbolPrefix : ''),
218
- replacedNumber,
219
- escapeQuotes(symbolSuffix !== null && symbolSuffix !== void 0 ? symbolSuffix : ''),
220
- closingBraquet !== null && closingBraquet !== void 0 ? closingBraquet : '',
221
- escapeQuotes(suffix !== null && suffix !== void 0 ? suffix : '')
222
- ].join('');
223
- return format.replace(',', '\,');
224
- }
225
- function createExcelFormatFromGridFormatter(columnDef, grid, formatterType, groupType = '') {
226
- let outputFormat = '';
227
- let positiveFormat = '';
228
- let negativeFormat = '';
229
- const { minDecimal, maxDecimal, thousandSeparator } = getNumericFormatterOptions(columnDef, grid, formatterType);
230
- const leftInteger = thousandSeparator ? '2220' : '0';
231
- const testingNo = parseFloat(`${leftInteger}.${excelTestingDecimalNumberPadding(minDecimal, maxDecimal)}`);
232
- if (formatterType === 'group' && columnDef.groupTotalsFormatter) {
233
- positiveFormat = (0, common_1.sanitizeHtmlToText)(columnDef.groupTotalsFormatter({ [groupType]: { [columnDef.field]: testingNo } }, columnDef, grid));
234
- negativeFormat = (0, common_1.sanitizeHtmlToText)(columnDef.groupTotalsFormatter({ [groupType]: { [columnDef.field]: -testingNo } }, columnDef, grid));
235
- }
236
- else if (columnDef.formatter) {
237
- positiveFormat = (0, common_1.sanitizeHtmlToText)(columnDef.formatter(0, 0, testingNo, columnDef, {}, grid));
238
- negativeFormat = (0, common_1.sanitizeHtmlToText)(columnDef.formatter(0, 0, -testingNo, columnDef, {}, grid));
239
- }
240
- if (positiveFormat && negativeFormat) {
241
- outputFormat = createFormatFromNumber(positiveFormat) + ';' + createFormatFromNumber(negativeFormat);
242
- }
243
- return outputFormat;
244
- }
245
- function escapeQuotes(val) {
246
- return val ? `"${val}"` : val;
247
- }
248
- /** Get number format for a number cell, for example { minDecimal: 2, maxDecimal: 5 } will return "00###" */
249
- function excelTestingDecimalNumberPadding(minDecimal, maxDecimal) {
250
- return textPadding('1', minDecimal) + textPadding('2', maxDecimal - minDecimal);
251
- }
252
- function textPadding(numberStr, count) {
253
- let output = '';
254
- for (let i = 0; i < count; i++) {
255
- output += numberStr;
256
- }
257
- return output;
258
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExcelFormatFromGridFormatter = exports.getFormatterNumericDataType = exports.getNumericFormatterOptions = exports.getGroupTotalValue = exports.useCellFormatByFieldType = exports.parseNumberWithFormatterOptions = exports.getExcelNumberCallback = exports.getExcelSameInputDataCallback = void 0;
4
+ const common_1 = require("@slickgrid-universal/common");
5
+ // define all type of potential excel data function callbacks
6
+ const getExcelSameInputDataCallback = (data) => data;
7
+ exports.getExcelSameInputDataCallback = getExcelSameInputDataCallback;
8
+ const getExcelNumberCallback = (data, column, excelFormatterId, _excelSheet, gridOptions) => ({
9
+ value: typeof data === 'string' && /\d/g.test(data) ? parseNumberWithFormatterOptions(data, column, gridOptions) : data,
10
+ metadata: { style: excelFormatterId }
11
+ });
12
+ exports.getExcelNumberCallback = getExcelNumberCallback;
13
+ /** Parse a number which the user might have provided formatter options (for example a user might have provided { decimalSeparator: ',', thousandSeparator: ' '}) */
14
+ function parseNumberWithFormatterOptions(value, column, gridOptions) {
15
+ let outValue = value;
16
+ if (typeof value === 'string' && value) {
17
+ const decimalSeparator = (0, common_1.getValueFromParamsOrFormatterOptions)('decimalSeparator', column, gridOptions, common_1.Constants.DEFAULT_NUMBER_DECIMAL_SEPARATOR);
18
+ const val = (decimalSeparator === ',')
19
+ ? parseFloat(value.replace(/[^0-9\,]+/g, '').replace(',', '.'))
20
+ : parseFloat(value.replace(/[^\d\.]/g, ''));
21
+ outValue = isNaN(val) ? value : val;
22
+ }
23
+ return outValue;
24
+ }
25
+ exports.parseNumberWithFormatterOptions = parseNumberWithFormatterOptions;
26
+ /** use different Excel Stylesheet Format as per the Field Type */
27
+ function useCellFormatByFieldType(stylesheet, stylesheetFormatters, columnDef, grid) {
28
+ const fieldType = (0, common_1.getColumnFieldType)(columnDef);
29
+ let stylesheetFormatterId;
30
+ let callback = exports.getExcelSameInputDataCallback;
31
+ if (fieldType === common_1.FieldType.number) {
32
+ stylesheetFormatterId = getExcelFormatFromGridFormatter(stylesheet, stylesheetFormatters, columnDef, grid, 'cell').stylesheetFormatter.id;
33
+ callback = exports.getExcelNumberCallback;
34
+ }
35
+ return { stylesheetFormatterId, getDataValueParser: callback };
36
+ }
37
+ exports.useCellFormatByFieldType = useCellFormatByFieldType;
38
+ function getGroupTotalValue(totals, columnDef, groupType) {
39
+ var _a, _b;
40
+ return (_b = (_a = totals === null || totals === void 0 ? void 0 : totals[groupType]) === null || _a === void 0 ? void 0 : _a[columnDef.field]) !== null && _b !== void 0 ? _b : 0;
41
+ }
42
+ exports.getGroupTotalValue = getGroupTotalValue;
43
+ /** Get numeric formatter options when defined or use default values (minDecimal, maxDecimal, thousandSeparator, decimalSeparator, wrapNegativeNumber) */
44
+ function getNumericFormatterOptions(columnDef, grid, formatterType) {
45
+ var _a;
46
+ let dataType;
47
+ if (formatterType === 'group') {
48
+ switch (columnDef.groupTotalsFormatter) {
49
+ case common_1.GroupTotalFormatters.avgTotalsCurrency:
50
+ case common_1.GroupTotalFormatters.avgTotalsDollar:
51
+ case common_1.GroupTotalFormatters.sumTotalsCurrency:
52
+ case common_1.GroupTotalFormatters.sumTotalsCurrencyColored:
53
+ case common_1.GroupTotalFormatters.sumTotalsDollar:
54
+ case common_1.GroupTotalFormatters.sumTotalsDollarBold:
55
+ case common_1.GroupTotalFormatters.sumTotalsDollarColored:
56
+ case common_1.GroupTotalFormatters.sumTotalsDollarColoredBold:
57
+ dataType = 'currency';
58
+ break;
59
+ case common_1.GroupTotalFormatters.avgTotalsPercentage:
60
+ dataType = 'percent';
61
+ break;
62
+ case common_1.GroupTotalFormatters.avgTotals:
63
+ case common_1.GroupTotalFormatters.minTotals:
64
+ case common_1.GroupTotalFormatters.maxTotals:
65
+ case common_1.GroupTotalFormatters.sumTotals:
66
+ case common_1.GroupTotalFormatters.sumTotalsColored:
67
+ case common_1.GroupTotalFormatters.sumTotalsBold:
68
+ default:
69
+ // side note, formatters are using "regular" without any decimal limits (min, max),
70
+ // however in Excel export with custom format that doesn't work so well, we should use "decimal" to at least show optional decimals with "##"
71
+ dataType = 'decimal';
72
+ break;
73
+ }
74
+ }
75
+ else {
76
+ // when formatter is a Formatter.multiple, we need to loop through each of its formatter to find the best numeric data type
77
+ if (columnDef.formatter === common_1.Formatters.multiple && Array.isArray((_a = columnDef.params) === null || _a === void 0 ? void 0 : _a.formatters)) {
78
+ dataType = 'decimal';
79
+ for (const formatter of columnDef.params.formatters) {
80
+ dataType = getFormatterNumericDataType(formatter);
81
+ if (dataType !== 'decimal') {
82
+ break; // if we found something different than the default (decimal) then we can assume that we found our type so we can stop & return
83
+ }
84
+ }
85
+ }
86
+ else {
87
+ dataType = getFormatterNumericDataType(columnDef.formatter);
88
+ }
89
+ }
90
+ return (0, common_1.retrieveFormatterOptions)(columnDef, grid, dataType, formatterType);
91
+ }
92
+ exports.getNumericFormatterOptions = getNumericFormatterOptions;
93
+ function getFormatterNumericDataType(formatter) {
94
+ let dataType;
95
+ switch (formatter) {
96
+ case common_1.Formatters.currency:
97
+ case common_1.Formatters.dollar:
98
+ case common_1.Formatters.dollarColored:
99
+ case common_1.Formatters.dollarColoredBold:
100
+ dataType = 'currency';
101
+ break;
102
+ case common_1.Formatters.percent:
103
+ case common_1.Formatters.percentComplete:
104
+ case common_1.Formatters.percentCompleteBar:
105
+ case common_1.Formatters.percentCompleteBarWithText:
106
+ case common_1.Formatters.percentSymbol:
107
+ dataType = 'percent';
108
+ break;
109
+ case common_1.Formatters.decimal:
110
+ default:
111
+ // use "decimal" instead of "regular" to show optional decimals "##" in Excel
112
+ dataType = 'decimal';
113
+ break;
114
+ }
115
+ return dataType;
116
+ }
117
+ exports.getFormatterNumericDataType = getFormatterNumericDataType;
118
+ function getExcelFormatFromGridFormatter(stylesheet, stylesheetFormatters, columnDef, grid, formatterType) {
119
+ var _a;
120
+ let format = '';
121
+ let groupType = '';
122
+ let stylesheetFormatter;
123
+ const fieldType = (0, common_1.getColumnFieldType)(columnDef);
124
+ if (formatterType === 'group') {
125
+ switch (columnDef.groupTotalsFormatter) {
126
+ case common_1.GroupTotalFormatters.avgTotals:
127
+ case common_1.GroupTotalFormatters.avgTotalsCurrency:
128
+ case common_1.GroupTotalFormatters.avgTotalsDollar:
129
+ case common_1.GroupTotalFormatters.avgTotalsPercentage:
130
+ groupType = 'avg';
131
+ break;
132
+ case common_1.GroupTotalFormatters.minTotals:
133
+ groupType = 'min';
134
+ break;
135
+ case common_1.GroupTotalFormatters.maxTotals:
136
+ groupType = 'max';
137
+ break;
138
+ case common_1.GroupTotalFormatters.sumTotals:
139
+ case common_1.GroupTotalFormatters.sumTotalsBold:
140
+ case common_1.GroupTotalFormatters.sumTotalsColored:
141
+ case common_1.GroupTotalFormatters.sumTotalsCurrency:
142
+ case common_1.GroupTotalFormatters.sumTotalsCurrencyColored:
143
+ case common_1.GroupTotalFormatters.sumTotalsDollar:
144
+ case common_1.GroupTotalFormatters.sumTotalsDollarColoredBold:
145
+ case common_1.GroupTotalFormatters.sumTotalsDollarColored:
146
+ case common_1.GroupTotalFormatters.sumTotalsDollarBold:
147
+ groupType = 'sum';
148
+ break;
149
+ default:
150
+ stylesheetFormatter = stylesheetFormatters.numberFormatter;
151
+ break;
152
+ }
153
+ }
154
+ else {
155
+ switch (fieldType) {
156
+ case common_1.FieldType.number:
157
+ switch (columnDef.formatter) {
158
+ case common_1.Formatters.multiple:
159
+ // when formatter is a Formatter.multiple, we need to loop through each of its formatter to find the best possible Excel format
160
+ if (Array.isArray((_a = columnDef.params) === null || _a === void 0 ? void 0 : _a.formatters)) {
161
+ for (const formatter of columnDef.params.formatters) {
162
+ const { stylesheetFormatter: stylesheetFormatterResult } = getExcelFormatFromGridFormatter(stylesheet, stylesheetFormatters, { ...columnDef, formatter }, grid, formatterType);
163
+ if (stylesheetFormatterResult !== stylesheetFormatters.numberFormatter) {
164
+ stylesheetFormatter = stylesheetFormatterResult;
165
+ break;
166
+ }
167
+ }
168
+ }
169
+ if (!stylesheetFormatter) {
170
+ stylesheetFormatter = stylesheetFormatters.numberFormatter;
171
+ }
172
+ break;
173
+ case common_1.Formatters.currency:
174
+ case common_1.Formatters.decimal:
175
+ case common_1.Formatters.dollar:
176
+ case common_1.Formatters.dollarColored:
177
+ case common_1.Formatters.dollarColoredBold:
178
+ case common_1.Formatters.percent:
179
+ case common_1.Formatters.percentComplete:
180
+ case common_1.Formatters.percentCompleteBar:
181
+ case common_1.Formatters.percentCompleteBarWithText:
182
+ case common_1.Formatters.percentSymbol:
183
+ format = createExcelFormatFromGridFormatter(columnDef, grid, 'cell');
184
+ break;
185
+ default:
186
+ stylesheetFormatter = stylesheetFormatters.numberFormatter;
187
+ break;
188
+ }
189
+ break;
190
+ }
191
+ }
192
+ if (!stylesheetFormatter && (columnDef.formatter || columnDef.groupTotalsFormatter)) {
193
+ format = createExcelFormatFromGridFormatter(columnDef, grid, formatterType, groupType);
194
+ if (!stylesheetFormatters.hasOwnProperty(format)) {
195
+ stylesheetFormatters[format] = stylesheet.createFormat({ format }); // save new formatter with its format as a prop key
196
+ }
197
+ stylesheetFormatter = stylesheetFormatters[format];
198
+ }
199
+ return { stylesheetFormatter: stylesheetFormatter, groupType };
200
+ }
201
+ exports.getExcelFormatFromGridFormatter = getExcelFormatFromGridFormatter;
202
+ // --
203
+ // private functions
204
+ // ------------------
205
+ function createFormatFromNumber(formattedVal) {
206
+ // full number syntax can have up to 7 sections, for example::
207
+ // Total: ($10,420.55 USD) Expensed
208
+ const [
209
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
210
+ _, prefix, openBraquet, symbolPrefix, number, symbolSuffix, closingBraquet, suffix] = (formattedVal === null || formattedVal === void 0 ? void 0 : formattedVal.match(/^([^\d\(\-]*)([\(]?)([^\d]*)([\-]?[\w]]?[\d\s]*[.,\d]*[\d]*[^)\s\%]?)([^\d.,)]*)([\)]?)([^\d]*)$/i)) || [];
211
+ // we use 1 so that they won't be removed when rounding numbers, however Excel uses 0 and # symbol
212
+ // replace 1's by 0's (required numbers) and replace 2's by "#" (optional numbers)
213
+ const replacedNumber = (number || '').replace(/1/g, '0').replace(/[2]/g, '#');
214
+ const format = [
215
+ escapeQuotes(prefix !== null && prefix !== void 0 ? prefix : ''),
216
+ openBraquet !== null && openBraquet !== void 0 ? openBraquet : '',
217
+ escapeQuotes(symbolPrefix !== null && symbolPrefix !== void 0 ? symbolPrefix : ''),
218
+ replacedNumber,
219
+ escapeQuotes(symbolSuffix !== null && symbolSuffix !== void 0 ? symbolSuffix : ''),
220
+ closingBraquet !== null && closingBraquet !== void 0 ? closingBraquet : '',
221
+ escapeQuotes(suffix !== null && suffix !== void 0 ? suffix : '')
222
+ ].join('');
223
+ return format.replace(',', '\,');
224
+ }
225
+ function createExcelFormatFromGridFormatter(columnDef, grid, formatterType, groupType = '') {
226
+ let outputFormat = '';
227
+ let positiveFormat = '';
228
+ let negativeFormat = '';
229
+ const { minDecimal, maxDecimal, thousandSeparator } = getNumericFormatterOptions(columnDef, grid, formatterType);
230
+ const leftInteger = thousandSeparator ? '2220' : '0';
231
+ const testingNo = parseFloat(`${leftInteger}.${excelTestingDecimalNumberPadding(minDecimal, maxDecimal)}`);
232
+ if (formatterType === 'group' && columnDef.groupTotalsFormatter) {
233
+ positiveFormat = (0, common_1.sanitizeHtmlToText)(columnDef.groupTotalsFormatter({ [groupType]: { [columnDef.field]: testingNo } }, columnDef, grid));
234
+ negativeFormat = (0, common_1.sanitizeHtmlToText)(columnDef.groupTotalsFormatter({ [groupType]: { [columnDef.field]: -testingNo } }, columnDef, grid));
235
+ }
236
+ else if (columnDef.formatter) {
237
+ positiveFormat = (0, common_1.sanitizeHtmlToText)(columnDef.formatter(0, 0, testingNo, columnDef, {}, grid));
238
+ negativeFormat = (0, common_1.sanitizeHtmlToText)(columnDef.formatter(0, 0, -testingNo, columnDef, {}, grid));
239
+ }
240
+ if (positiveFormat && negativeFormat) {
241
+ outputFormat = createFormatFromNumber(positiveFormat) + ';' + createFormatFromNumber(negativeFormat);
242
+ }
243
+ return outputFormat;
244
+ }
245
+ function escapeQuotes(val) {
246
+ return val ? `"${val}"` : val;
247
+ }
248
+ /** Get number format for a number cell, for example { minDecimal: 2, maxDecimal: 5 } will return "00###" */
249
+ function excelTestingDecimalNumberPadding(minDecimal, maxDecimal) {
250
+ return textPadding('1', minDecimal) + textPadding('2', maxDecimal - minDecimal);
251
+ }
252
+ function textPadding(numberStr, count) {
253
+ let output = '';
254
+ for (let i = 0; i < count; i++) {
255
+ output += numberStr;
256
+ }
257
+ return output;
258
+ }
259
259
  //# sourceMappingURL=excelUtils.js.map
@@ -1,6 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExcelExportService = void 0;
4
- var excelExport_service_1 = require("./excelExport.service");
5
- Object.defineProperty(exports, "ExcelExportService", { enumerable: true, get: function () { return excelExport_service_1.ExcelExportService; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExcelExportService = void 0;
4
+ var excelExport_service_1 = require("./excelExport.service");
5
+ Object.defineProperty(exports, "ExcelExportService", { enumerable: true, get: function () { return excelExport_service_1.ExcelExportService; } });
6
6
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=excelCellFormat.interface.js.map
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=excelMetadata.interface.js.map
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=excelStylesheet.interface.js.map
@@ -1,20 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./excelCellFormat.interface"), exports);
18
- __exportStar(require("./excelMetadata.interface"), exports);
19
- __exportStar(require("./excelStylesheet.interface"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./excelCellFormat.interface"), exports);
18
+ __exportStar(require("./excelMetadata.interface"), exports);
19
+ __exportStar(require("./excelStylesheet.interface"), exports);
20
20
  //# sourceMappingURL=index.js.map