@sme.up/doc-alchemist 1.3.0 → 1.4.0-CommonJS-20251015134706
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/README.md +1 -1
- package/dist/assets/gfx-data.js +4 -1
- package/dist/assets/gfx-data.js.map +1 -1
- package/dist/converters/excel/commons.d.ts +2 -2
- package/dist/converters/excel/commons.js +49 -33
- package/dist/converters/excel/commons.js.map +1 -1
- package/dist/converters/excel/excel-converter.types.js +14 -11
- package/dist/converters/excel/excel-converter.types.js.map +1 -1
- package/dist/converters/excel/matrix-converter.d.ts +3 -3
- package/dist/converters/excel/matrix-converter.js +46 -36
- package/dist/converters/excel/matrix-converter.js.map +1 -1
- package/dist/converters/excel/tree-converter.d.ts +2 -2
- package/dist/converters/excel/tree-converter.js +33 -25
- package/dist/converters/excel/tree-converter.js.map +1 -1
- package/dist/converters/excel-converter.d.ts +3 -3
- package/dist/converters/excel-converter.js +18 -13
- package/dist/converters/excel-converter.js.map +1 -1
- package/dist/converters/images/charts-generator.d.ts +2 -2
- package/dist/converters/images/charts-generator.js +41 -4
- package/dist/converters/images/charts-generator.js.map +1 -1
- package/dist/converters/pdf/autotable-renderer.d.ts +2 -2
- package/dist/converters/pdf/autotable-renderer.js +7 -3
- package/dist/converters/pdf/autotable-renderer.js.map +1 -1
- package/dist/converters/pdf/cover-renderer.js +41 -4
- package/dist/converters/pdf/cover-renderer.js.map +1 -1
- package/dist/converters/pdf/formulas-helper.d.ts +2 -2
- package/dist/converters/pdf/formulas-helper.js +37 -28
- package/dist/converters/pdf/formulas-helper.js.map +1 -1
- package/dist/converters/pdf/matrix-converter.d.ts +2 -2
- package/dist/converters/pdf/matrix-converter.js +52 -12
- package/dist/converters/pdf/matrix-converter.js.map +1 -1
- package/dist/converters/pdf/pdf-converter.types.js +2 -1
- package/dist/converters/pdf/pdf-converter.types.js.map +1 -1
- package/dist/converters/pdf/sch-converter.d.ts +1 -1
- package/dist/converters/pdf/sch-converter.js +43 -6
- package/dist/converters/pdf/sch-converter.js.map +1 -1
- package/dist/converters/pdf-converter.d.ts +3 -3
- package/dist/converters/pdf-converter.js +23 -18
- package/dist/converters/pdf-converter.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/types/component-props.js +5 -2
- package/dist/types/component-props.js.map +1 -1
- package/dist/types/component.js +7 -4
- package/dist/types/component.js.map +1 -1
- package/dist/types/converter.js +2 -1
- package/dist/types/converter.js.map +1 -1
- package/dist/types/data-structures/smeupDataStructure.d.ts +4 -4
- package/dist/types/data-structures/smeupDataStructure.js +16 -12
- package/dist/types/data-structures/smeupDataStructure.js.map +1 -1
- package/dist/types/data-structures/smeupDataTable.d.ts +1 -1
- package/dist/types/data-structures/smeupDataTable.js +4 -1
- package/dist/types/data-structures/smeupDataTable.js.map +1 -1
- package/dist/types/data-structures/smeupDataTree.d.ts +2 -2
- package/dist/types/data-structures/smeupDataTree.js +2 -1
- package/dist/types/data-structures/smeupDataTree.js.map +1 -1
- package/dist/types/data-structures/smeupSch.d.ts +6 -6
- package/dist/types/data-structures/smeupSch.js +5 -2
- package/dist/types/data-structures/smeupSch.js.map +1 -1
- package/dist/types/dynamism.d.ts +1 -1
- package/dist/types/dynamism.js +7 -4
- package/dist/types/dynamism.js.map +1 -1
- package/dist/types/general.js +7 -2
- package/dist/types/general.js.map +1 -1
- package/dist/types/helpers.js +5 -2
- package/dist/types/helpers.js.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.js +7 -4
- package/dist/types/index.js.map +1 -1
- package/dist/utils/commons-utility.d.ts +4 -3
- package/dist/utils/commons-utility.js +136 -43
- package/dist/utils/commons-utility.js.map +1 -1
- package/dist/utils/datastructure-utility.d.ts +1 -1
- package/dist/utils/datastructure-utility.js +5 -1
- package/dist/utils/datastructure-utility.js.map +1 -1
- package/dist/utils/dates-utility.js +37 -27
- package/dist/utils/dates-utility.js.map +1 -1
- package/dist/utils/formatter-utility.d.ts +1 -1
- package/dist/utils/formatter-utility.js +9 -3
- package/dist/utils/formatter-utility.js.map +1 -1
- package/dist/utils/image-utils.js +10 -3
- package/dist/utils/image-utils.js.map +1 -1
- package/dist/utils/math-utility.js +46 -29
- package/dist/utils/math-utility.js.map +1 -1
- package/dist/utils/objects-utility.d.ts +1 -1
- package/dist/utils/objects-utility.js +9 -3
- package/dist/utils/objects-utility.js.map +1 -1
- package/dist/utils/regex-utility.js +4 -1
- package/dist/utils/regex-utility.js.map +1 -1
- package/package.json +1 -2
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isGroupedCell = exports.groupedCellFormatAttributes = exports.getCellsFromRange = exports.getDistinctCount = exports.smeupFormulaToExcelValue = exports.smeupFormulaToExcelFormula = exports.getTotalFormula = exports.getExcelColumnLetter = exports.addFooterTotalsRow = exports.setHeaderStyling = exports.initializeWorksheet = void 0;
|
|
7
|
+
const exceljs_1 = __importDefault(require("exceljs"));
|
|
8
|
+
const excel_converter_types_1 = require("./excel-converter.types");
|
|
9
|
+
const objects_utility_1 = require("../../utils/objects-utility");
|
|
10
|
+
const matrix_converter_1 = require("./matrix-converter");
|
|
11
|
+
const math_utility_1 = require("../../utils/math-utility");
|
|
12
|
+
const { ValueType } = exceljs_1.default;
|
|
7
13
|
/**
|
|
8
14
|
* Adds creator, creation date to the workbook and creates a sheet
|
|
9
15
|
* @param workbook
|
|
10
16
|
* @returns void
|
|
11
17
|
*/
|
|
12
|
-
|
|
18
|
+
const initializeWorksheet = (workbook) => {
|
|
13
19
|
workbook.creator = "/doc-alchemist - dataTable excel generator";
|
|
14
20
|
workbook.created = new Date();
|
|
15
21
|
const worksheet = workbook.addWorksheet("Export");
|
|
16
22
|
return worksheet;
|
|
17
23
|
};
|
|
18
|
-
|
|
24
|
+
exports.initializeWorksheet = initializeWorksheet;
|
|
25
|
+
const setHeaderStyling = (worksheet, background = false) => {
|
|
19
26
|
const headerRow = worksheet.getRow(1);
|
|
20
27
|
headerRow.font = { bold: true };
|
|
21
28
|
headerRow.alignment = {
|
|
@@ -26,11 +33,12 @@ export const setHeaderStyling = (worksheet, background = false) => {
|
|
|
26
33
|
if (background) {
|
|
27
34
|
for (let col = 1; col <= worksheet.columns.length; col++) {
|
|
28
35
|
const cell = headerRow.getCell(col);
|
|
29
|
-
cell.fill = headerStyleFill;
|
|
36
|
+
cell.fill = excel_converter_types_1.headerStyleFill;
|
|
30
37
|
}
|
|
31
38
|
}
|
|
32
39
|
};
|
|
33
|
-
|
|
40
|
+
exports.setHeaderStyling = setHeaderStyling;
|
|
41
|
+
const addFooterTotalsRow = (worksheet, columns, props, webupManagerData) => {
|
|
34
42
|
if (!props?.totals || typeof props.totals !== "object") {
|
|
35
43
|
return;
|
|
36
44
|
}
|
|
@@ -40,7 +48,7 @@ export const addFooterTotalsRow = (worksheet, columns, props, webupManagerData)
|
|
|
40
48
|
const totalOperation = totals[column.name];
|
|
41
49
|
if (!totalOperation)
|
|
42
50
|
return;
|
|
43
|
-
const formula = getTotalFormula(worksheet, totalOperation, columnIndex + 1, // from base 0 to base 1
|
|
51
|
+
const formula = (0, exports.getTotalFormula)(worksheet, totalOperation, columnIndex + 1, // from base 0 to base 1
|
|
44
52
|
worksheet.rowCount, columns, totalOperation.startsWith("MATH"));
|
|
45
53
|
return formula ? { formula: formula, type: ValueType.Formula } : " ";
|
|
46
54
|
});
|
|
@@ -50,19 +58,20 @@ export const addFooterTotalsRow = (worksheet, columns, props, webupManagerData)
|
|
|
50
58
|
footerRow.alignment = { horizontal: "right" };
|
|
51
59
|
columns.map((column, index) => {
|
|
52
60
|
const exceljsCell = footerRow.getCell(index + 1); // Convert base 0 index to base 1
|
|
53
|
-
exceljsCell.fill = footerStyleFill;
|
|
61
|
+
exceljsCell.fill = excel_converter_types_1.footerStyleFill;
|
|
54
62
|
if (column.obj &&
|
|
55
|
-
objectsIsDate(column.obj) &&
|
|
56
|
-
(exceljsCell.formula?.startsWith(allowedTotals.Min) ||
|
|
57
|
-
exceljsCell.formula?.startsWith(allowedTotals.Max))) {
|
|
63
|
+
(0, objects_utility_1.objectsIsDate)(column.obj) &&
|
|
64
|
+
(exceljsCell.formula?.startsWith(excel_converter_types_1.allowedTotals.Min) ||
|
|
65
|
+
exceljsCell.formula?.startsWith(excel_converter_types_1.allowedTotals.Max))) {
|
|
58
66
|
const dateFormat = webupManagerData.datesLocale === "it" ? "dd/mm/yyyy" : "mm/dd/yyyy";
|
|
59
67
|
exceljsCell.numFmt = dateFormat;
|
|
60
68
|
return;
|
|
61
69
|
}
|
|
62
|
-
exceljsCell.numFmt = getExcelNumFormatForGroupedRow(column, totals);
|
|
70
|
+
exceljsCell.numFmt = (0, matrix_converter_1.getExcelNumFormatForGroupedRow)(column, totals);
|
|
63
71
|
});
|
|
64
72
|
};
|
|
65
|
-
|
|
73
|
+
exports.addFooterTotalsRow = addFooterTotalsRow;
|
|
74
|
+
const getExcelColumnLetter = (index) => {
|
|
66
75
|
let columnLetter = "";
|
|
67
76
|
while (index > 0) {
|
|
68
77
|
index--; // Excel columns are 1-based, but calculations work better with 0-based
|
|
@@ -71,6 +80,7 @@ export const getExcelColumnLetter = (index) => {
|
|
|
71
80
|
}
|
|
72
81
|
return columnLetter;
|
|
73
82
|
};
|
|
83
|
+
exports.getExcelColumnLetter = getExcelColumnLetter;
|
|
74
84
|
/**
|
|
75
85
|
* Returns the formula used in the footer to add Totals at the end of the table
|
|
76
86
|
* @param totalOperation string
|
|
@@ -78,29 +88,30 @@ export const getExcelColumnLetter = (index) => {
|
|
|
78
88
|
* @param rowNumber number
|
|
79
89
|
* @returns
|
|
80
90
|
*/
|
|
81
|
-
|
|
91
|
+
const getTotalFormula = (worksheet, totalOperation, colIndex, rowNumber, filteredColumns, isSmeupFormula) => {
|
|
82
92
|
const startRow = 2;
|
|
83
|
-
const columnExcelLetter = getExcelColumnLetter(colIndex);
|
|
93
|
+
const columnExcelLetter = (0, exports.getExcelColumnLetter)(colIndex);
|
|
84
94
|
if (isSmeupFormula) {
|
|
85
|
-
return smeupFormulaToExcelFormula(totalOperation, rowNumber, filteredColumns);
|
|
95
|
+
return (0, exports.smeupFormulaToExcelFormula)(totalOperation, rowNumber, filteredColumns);
|
|
86
96
|
}
|
|
87
|
-
if (!allowedTotals[totalOperation]) {
|
|
97
|
+
if (!excel_converter_types_1.allowedTotals[totalOperation]) {
|
|
88
98
|
console.warn(`Total operation [' ${totalOperation} '] is not supported`, "exportUtils.ts");
|
|
89
99
|
return "";
|
|
90
100
|
}
|
|
91
101
|
if (totalOperation === "Distinct") {
|
|
92
|
-
return getDistinctCount(`${columnExcelLetter}${startRow}:${columnExcelLetter}${rowNumber}`, worksheet);
|
|
102
|
+
return (0, exports.getDistinctCount)(`${columnExcelLetter}${startRow}:${columnExcelLetter}${rowNumber}`, worksheet);
|
|
93
103
|
}
|
|
94
104
|
else {
|
|
95
|
-
return `${allowedTotals[totalOperation]}${columnExcelLetter}${startRow}:${columnExcelLetter}${rowNumber})`;
|
|
105
|
+
return `${excel_converter_types_1.allowedTotals[totalOperation]}${columnExcelLetter}${startRow}:${columnExcelLetter}${rowNumber})`;
|
|
96
106
|
}
|
|
97
107
|
};
|
|
98
|
-
|
|
108
|
+
exports.getTotalFormula = getTotalFormula;
|
|
109
|
+
const smeupFormulaToExcelFormula = (formula, rowNumber, filteredColumns) => {
|
|
99
110
|
const result = formula
|
|
100
111
|
.replace("MATH", "")
|
|
101
112
|
.replace(/\[([^\]]+)\]/g, (_, key) => {
|
|
102
113
|
const columnIndex = filteredColumns.findIndex(col => col.name === key) + 1;
|
|
103
|
-
const columnLetter = getExcelColumnLetter(columnIndex);
|
|
114
|
+
const columnLetter = (0, exports.getExcelColumnLetter)(columnIndex);
|
|
104
115
|
return columnLetter && columnIndex
|
|
105
116
|
? `${columnLetter}${rowNumber + 1}`
|
|
106
117
|
: key;
|
|
@@ -108,7 +119,8 @@ export const smeupFormulaToExcelFormula = (formula, rowNumber, filteredColumns)
|
|
|
108
119
|
.replaceAll(",", "."); // Replace eventual , to . => The excel accepted decimal separator
|
|
109
120
|
return result;
|
|
110
121
|
};
|
|
111
|
-
|
|
122
|
+
exports.smeupFormulaToExcelFormula = smeupFormulaToExcelFormula;
|
|
123
|
+
const smeupFormulaToExcelValue = (column, filteredColumns, cells) => {
|
|
112
124
|
let resultValue = "";
|
|
113
125
|
if (!column.formula) {
|
|
114
126
|
return "";
|
|
@@ -128,7 +140,7 @@ export const smeupFormulaToExcelValue = (column, filteredColumns, cells) => {
|
|
|
128
140
|
resultValue = applySUMFormula(column, filteredColumns, cells);
|
|
129
141
|
}
|
|
130
142
|
else {
|
|
131
|
-
resultValue = calculateExpression(result);
|
|
143
|
+
resultValue = (0, math_utility_1.calculateExpression)(result);
|
|
132
144
|
}
|
|
133
145
|
}
|
|
134
146
|
catch {
|
|
@@ -136,6 +148,7 @@ export const smeupFormulaToExcelValue = (column, filteredColumns, cells) => {
|
|
|
136
148
|
}
|
|
137
149
|
return resultValue.toString();
|
|
138
150
|
};
|
|
151
|
+
exports.smeupFormulaToExcelValue = smeupFormulaToExcelValue;
|
|
139
152
|
const applySUMFormula = (column, filteredColumns, cells) => {
|
|
140
153
|
let resultValue = 0;
|
|
141
154
|
resultValue = 0;
|
|
@@ -144,7 +157,7 @@ const applySUMFormula = (column, filteredColumns, cells) => {
|
|
|
144
157
|
if (col.obj && col.obj.t === "NR") {
|
|
145
158
|
let cellValue = 0;
|
|
146
159
|
if (col.formula) {
|
|
147
|
-
cellValue = Number(smeupFormulaToExcelValue(col, filteredColumns, cells));
|
|
160
|
+
cellValue = Number((0, exports.smeupFormulaToExcelValue)(col, filteredColumns, cells));
|
|
148
161
|
}
|
|
149
162
|
else {
|
|
150
163
|
cellValue = Number(cells[col.name]?.value);
|
|
@@ -156,7 +169,7 @@ const applySUMFormula = (column, filteredColumns, cells) => {
|
|
|
156
169
|
});
|
|
157
170
|
return resultValue;
|
|
158
171
|
};
|
|
159
|
-
|
|
172
|
+
const getDistinctCount = (range, worksheet) => {
|
|
160
173
|
const column = range.split(":")[0].replace(/[0-9]/g, ""); // Extract column letter
|
|
161
174
|
const startRow = parseInt(range.split(":")[0].replace(/\D/g, ""), 10);
|
|
162
175
|
const endRow = parseInt(range.split(":")[1].replace(/\D/g, ""), 10);
|
|
@@ -173,6 +186,7 @@ export const getDistinctCount = (range, worksheet) => {
|
|
|
173
186
|
}
|
|
174
187
|
return uniqueValues.size.toString();
|
|
175
188
|
};
|
|
189
|
+
exports.getDistinctCount = getDistinctCount;
|
|
176
190
|
/**
|
|
177
191
|
* Estrae tutte le celle (ExcelJS.Cell) da un intervallo rettangolare specificato in un worksheet ExcelJS.
|
|
178
192
|
*
|
|
@@ -184,7 +198,7 @@ export const getDistinctCount = (range, worksheet) => {
|
|
|
184
198
|
* @param endRef - Il riferimento della cella finale (es. "C3").
|
|
185
199
|
* @returns Un array di ExcelJS.Cell dall'intervallo specificato, in ordine riga-major.
|
|
186
200
|
*/
|
|
187
|
-
|
|
201
|
+
const getCellsFromRange = (worksheet, startRef, endRef) => {
|
|
188
202
|
const parseCellRef = (ref) => {
|
|
189
203
|
const match = ref.match(/^([A-Z]+)(\d+)$/i);
|
|
190
204
|
if (!match)
|
|
@@ -213,7 +227,8 @@ export const getCellsFromRange = (worksheet, startRef, endRef) => {
|
|
|
213
227
|
}
|
|
214
228
|
return cells;
|
|
215
229
|
};
|
|
216
|
-
|
|
230
|
+
exports.getCellsFromRange = getCellsFromRange;
|
|
231
|
+
exports.groupedCellFormatAttributes = {
|
|
217
232
|
font: { bold: true },
|
|
218
233
|
alignment: { horizontal: "left" },
|
|
219
234
|
fill: {
|
|
@@ -222,11 +237,12 @@ export const groupedCellFormatAttributes = {
|
|
|
222
237
|
fgColor: { argb: "ffe0e0e0" },
|
|
223
238
|
},
|
|
224
239
|
};
|
|
225
|
-
|
|
240
|
+
const isGroupedCell = (cell) => {
|
|
226
241
|
return (JSON.stringify({
|
|
227
242
|
font: cell.font,
|
|
228
243
|
alignment: cell.alignment,
|
|
229
244
|
fill: cell.fill,
|
|
230
|
-
}) === JSON.stringify(groupedCellFormatAttributes));
|
|
245
|
+
}) === JSON.stringify(exports.groupedCellFormatAttributes));
|
|
231
246
|
};
|
|
247
|
+
exports.isGroupedCell = isGroupedCell;
|
|
232
248
|
//# sourceMappingURL=commons.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commons.js","sourceRoot":"","sources":["../../../src/converters/excel/commons.ts"],"names":[],"mappings":"AAAA,OAAO,OAAuC,MAAM,SAAS,CAAC;AAC9D,OAAO,EACL,aAAa,EACb,eAAe,EACf,eAAe,GAChB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAKvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;AAE9B;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAA0B,EAAE,EAAE;IAChE,QAAQ,CAAC,OAAO,GAAG,4CAA4C,CAAC;IAChE,QAAQ,CAAC,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;IAE9B,MAAM,SAAS,GAAG,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAClD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,SAAoB,EACpB,UAAU,GAAG,KAAK,EACZ,EAAE;IACR,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I,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;IACpB,SAAS,EAAE,EAAE,UAAU,EAAE,MAAM,EAAwB;IACvD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE;KACtB;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAkB,EAAW,EAAE;IAC3D,OAAO,CACL,IAAI,CAAC,SAAS,CAAC;QACb,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,2BAA2B,CAAC,CACnD,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import ExcelJS, { Alignment, Fill, Worksheet } from \"exceljs\";\nimport {\n allowedTotals,\n footerStyleFill,\n headerStyleFill,\n} from \"./excel-converter.types.js\";\nimport { GenericObject, WebupManagerData } from \"../../types/index.js\";\nimport { objectsIsDate } from \"../../utils/objects-utility.js\";\nimport { getExcelNumFormatForGroupedRow } from \"./matrix-converter.js\";\nimport {\n SmeupDataCell,\n SmeupDataColumn,\n} from \"../../types/data-structures/smeupDataTable.js\";\nimport { calculateExpression } from \"../../utils/math-utility.js\";\nconst { ValueType } = ExcelJS;\n\n/**\n * Adds creator, creation date to the workbook and creates a sheet\n * @param workbook\n * @returns void\n */\nexport const initializeWorksheet = (workbook: ExcelJS.Workbook) => {\n workbook.creator = \"/doc-alchemist - dataTable excel generator\";\n workbook.created = new Date();\n\n const worksheet = workbook.addWorksheet(\"Export\");\n return worksheet;\n};\n\nexport const setHeaderStyling = (\n worksheet: Worksheet,\n background = false,\n): void => {\n const headerRow = worksheet.getRow(1);\n headerRow.font = { bold: true };\n headerRow.alignment = {\n horizontal: \"center\",\n vertical: \"middle\",\n wrapText: true,\n };\n\n if (background) {\n for (let col = 1; col <= worksheet.columns.length; col++) {\n const cell = headerRow.getCell(col);\n cell.fill = headerStyleFill;\n }\n }\n};\n\nexport const addFooterTotalsRow = (\n worksheet: ExcelJS.Worksheet,\n columns: SmeupDataColumn[],\n props: GenericObject,\n webupManagerData: WebupManagerData,\n) => {\n if (!props?.totals || typeof props.totals !== \"object\") {\n return;\n }\n\n const totals = props.totals as Record<string, string>;\n\n // Set footer total formulas\n const footerRowData = columns.map((column, columnIndex) => {\n const totalOperation: string = totals[column.name];\n if (!totalOperation) return;\n\n const formula = getTotalFormula(\n worksheet,\n totalOperation,\n columnIndex + 1, // from base 0 to base 1\n worksheet.rowCount,\n columns,\n totalOperation.startsWith(\"MATH\"),\n );\n\n return formula ? { formula: formula, type: ValueType.Formula } : \" \";\n });\n const footerRow = worksheet.addRow(footerRowData);\n\n // Format excel footer cells\n footerRow.font = { bold: true };\n footerRow.alignment = { horizontal: \"right\" };\n columns.map((column, index) => {\n const exceljsCell = footerRow.getCell(index + 1); // Convert base 0 index to base 1\n exceljsCell.fill = footerStyleFill;\n\n if (\n column.obj &&\n objectsIsDate(column.obj) &&\n (exceljsCell.formula?.startsWith(allowedTotals.Min) ||\n exceljsCell.formula?.startsWith(allowedTotals.Max))\n ) {\n const dateFormat =\n webupManagerData.datesLocale === \"it\" ? \"dd/mm/yyyy\" : \"mm/dd/yyyy\";\n exceljsCell.numFmt = dateFormat;\n return;\n }\n\n exceljsCell.numFmt = getExcelNumFormatForGroupedRow(column, totals);\n });\n};\n\nexport const getExcelColumnLetter = (index: number): string => {\n let columnLetter = \"\";\n while (index > 0) {\n index--; // Excel columns are 1-based, but calculations work better with 0-based\n columnLetter = String.fromCharCode((index % 26) + 65) + columnLetter;\n index = Math.floor(index / 26);\n }\n return columnLetter;\n};\n\n/**\n * Returns the formula used in the footer to add Totals at the end of the table\n * @param totalOperation string\n * @param colIndex string\n * @param rowNumber number\n * @returns\n */\nexport const getTotalFormula = (\n worksheet: ExcelJS.Worksheet,\n totalOperation: string,\n colIndex: number,\n rowNumber: number,\n filteredColumns: SmeupDataColumn[],\n isSmeupFormula: boolean,\n): string => {\n const startRow = 2;\n const columnExcelLetter = getExcelColumnLetter(colIndex);\n\n if (isSmeupFormula) {\n return smeupFormulaToExcelFormula(\n totalOperation,\n rowNumber,\n filteredColumns,\n );\n }\n\n if (!allowedTotals[totalOperation]) {\n console.warn(\n `Total operation [' ${totalOperation} '] is not supported`,\n \"exportUtils.ts\",\n );\n return \"\";\n }\n\n if (totalOperation === \"Distinct\") {\n return getDistinctCount(\n `${columnExcelLetter}${startRow}:${columnExcelLetter}${rowNumber}`,\n worksheet,\n );\n } else {\n return `${allowedTotals[totalOperation]}${columnExcelLetter}${startRow}:${columnExcelLetter}${rowNumber})`;\n }\n};\n\nexport const smeupFormulaToExcelFormula = (\n formula: string,\n rowNumber: number,\n filteredColumns: SmeupDataColumn[],\n): string => {\n const result = formula\n .replace(\"MATH\", \"\")\n .replace(/\\[([^\\]]+)\\]/g, (_, key) => {\n const columnIndex =\n filteredColumns.findIndex(col => col.name === key) + 1;\n const columnLetter = getExcelColumnLetter(columnIndex);\n return columnLetter && columnIndex\n ? `${columnLetter}${rowNumber + 1}`\n : key;\n })\n .replaceAll(\",\", \".\"); // Replace eventual , to . => The excel accepted decimal separator\n return result;\n};\n\nexport const smeupFormulaToExcelValue = (\n column: SmeupDataColumn,\n filteredColumns: SmeupDataColumn[],\n cells: Record<string, SmeupDataCell>,\n): string => {\n let resultValue: string | number = \"\";\n if (!column.formula) {\n return \"\";\n }\n const result = column.formula\n .replace(\"MATH\", \"\")\n .replace(/\\[([^\\]]+)\\]/g, (match, key) => {\n const columnIndex = filteredColumns.findIndex(col => col.name === key);\n return columnIndex >= 0\n ? (cells[key]?.value ?? \"\")\n : match === \"[SUM]\"\n ? match\n : key;\n });\n try {\n if (result === \"[SUM]\") {\n resultValue = applySUMFormula(column, filteredColumns, cells);\n } else {\n resultValue = calculateExpression(result);\n }\n } catch {\n resultValue = result; // If the formula fails, return the original formula\n }\n return resultValue.toString();\n};\n\nconst applySUMFormula = (\n column: SmeupDataColumn,\n filteredColumns: SmeupDataColumn[],\n cells: Record<string, SmeupDataCell>,\n): number => {\n let resultValue: number = 0;\n resultValue = 0;\n const index = filteredColumns.findIndex(col => col.name === column.name);\n filteredColumns.slice(0, index).forEach(col => {\n if (col.obj && col.obj.t === \"NR\") {\n let cellValue = 0;\n if (col.formula) {\n cellValue = Number(\n smeupFormulaToExcelValue(col, filteredColumns, cells),\n );\n } else {\n cellValue = Number(cells[col.name]?.value);\n }\n if (!isNaN(cellValue)) {\n resultValue = (resultValue as number) + cellValue;\n }\n }\n });\n return resultValue;\n};\n\nexport const getDistinctCount = (\n range: string,\n worksheet: ExcelJS.Worksheet,\n): string => {\n const column = range.split(\":\")[0].replace(/[0-9]/g, \"\"); // Extract column letter\n const startRow = parseInt(range.split(\":\")[0].replace(/\\D/g, \"\"), 10);\n const endRow = parseInt(range.split(\":\")[1].replace(/\\D/g, \"\"), 10);\n\n // Create a set to store unique values\n const uniqueValues = new Set<string>();\n\n for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {\n const cell = worksheet.getCell(`${column}${rowIndex}`);\n if (cell.formula) continue;\n const cellValue = cell.value;\n if (cellValue !== null && cellValue !== undefined) {\n uniqueValues.add(cellValue.toString());\n }\n }\n\n return uniqueValues.size.toString();\n};\n\n/**\n * Estrae tutte le celle (ExcelJS.Cell) da un intervallo rettangolare specificato in un worksheet ExcelJS.\n *\n * L'intervallo è definito dai riferimenti di cella iniziale e finale (es. \"A1\" a \"C3\").\n * Restituisce le celle in ordine riga-major.\n *\n * @param worksheet - Il worksheet ExcelJS da cui estrarre le celle.\n * @param startRef - Il riferimento della cella iniziale (es. \"A1\").\n * @param endRef - Il riferimento della cella finale (es. \"C3\").\n * @returns Un array di ExcelJS.Cell dall'intervallo specificato, in ordine riga-major.\n */\nexport const getCellsFromRange = (\n worksheet: ExcelJS.Worksheet,\n startRef: string,\n endRef: string,\n): ExcelJS.Cell[] => {\n const parseCellRef = (ref: string) => {\n const match = ref.match(/^([A-Z]+)(\\d+)$/i);\n if (!match) return null;\n const col = match[1].toUpperCase();\n const row = parseInt(match[2], 10);\n return { col, row };\n };\n const colToIndex = (col: string) => {\n let idx = 0;\n for (let i = 0; i < col.length; i++) {\n idx = idx * 26 + (col.charCodeAt(i) - 64);\n }\n return idx;\n };\n const start = parseCellRef(startRef);\n const end = parseCellRef(endRef);\n if (!start || !end) return [];\n const cells: ExcelJS.Cell[] = [];\n for (let r = start.row; r <= end.row; r++) {\n for (let c = colToIndex(start.col); c <= colToIndex(end.col); c++) {\n const cell = worksheet.getRow(r).getCell(c);\n cells.push(cell);\n }\n }\n return cells;\n};\n\nexport const groupedCellFormatAttributes = {\n font: { bold: true },\n alignment: { horizontal: \"left\" } as Partial<Alignment>,\n fill: {\n type: \"pattern\",\n pattern: \"solid\",\n fgColor: { argb: \"ffe0e0e0\" },\n } as Fill,\n};\n\nexport const isGroupedCell = (cell: ExcelJS.Cell): boolean => {\n return (\n JSON.stringify({\n font: cell.font,\n alignment: cell.alignment,\n fill: cell.fill,\n }) === JSON.stringify(groupedCellFormatAttributes)\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"commons.js","sourceRoot":"","sources":["../../../src/converters/excel/commons.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8D;AAC9D,mEAIiC;AAEjC,iEAA4D;AAC5D,yDAAoE;AAKpE,2DAA+D;AAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,iBAAO,CAAC;AAE9B;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CAAC,QA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AAC,SAAS,CAAC,mCAA2B,CAAC,CACnD,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB","sourcesContent":["import ExcelJS, { Alignment, Fill, Worksheet } from \"exceljs\";\nimport {\n allowedTotals,\n footerStyleFill,\n headerStyleFill,\n} from \"./excel-converter.types\";\nimport { GenericObject, WebupManagerData } from \"../../types/index\";\nimport { objectsIsDate } from \"../../utils/objects-utility\";\nimport { getExcelNumFormatForGroupedRow } from \"./matrix-converter\";\nimport {\n SmeupDataCell,\n SmeupDataColumn,\n} from \"../../types/data-structures/smeupDataTable\";\nimport { calculateExpression } from \"../../utils/math-utility\";\nconst { ValueType } = ExcelJS;\n\n/**\n * Adds creator, creation date to the workbook and creates a sheet\n * @param workbook\n * @returns void\n */\nexport const initializeWorksheet = (workbook: ExcelJS.Workbook) => {\n workbook.creator = \"/doc-alchemist - dataTable excel generator\";\n workbook.created = new Date();\n\n const worksheet = workbook.addWorksheet(\"Export\");\n return worksheet;\n};\n\nexport const setHeaderStyling = (\n worksheet: Worksheet,\n background = false,\n): void => {\n const headerRow = worksheet.getRow(1);\n headerRow.font = { bold: true };\n headerRow.alignment = {\n horizontal: \"center\",\n vertical: \"middle\",\n wrapText: true,\n };\n\n if (background) {\n for (let col = 1; col <= worksheet.columns.length; col++) {\n const cell = headerRow.getCell(col);\n cell.fill = headerStyleFill;\n }\n }\n};\n\nexport const addFooterTotalsRow = (\n worksheet: ExcelJS.Worksheet,\n columns: SmeupDataColumn[],\n props: GenericObject,\n webupManagerData: WebupManagerData,\n) => {\n if (!props?.totals || typeof props.totals !== \"object\") {\n return;\n }\n\n const totals = props.totals as Record<string, string>;\n\n // Set footer total formulas\n const footerRowData = columns.map((column, columnIndex) => {\n const totalOperation: string = totals[column.name];\n if (!totalOperation) return;\n\n const formula = getTotalFormula(\n worksheet,\n totalOperation,\n columnIndex + 1, // from base 0 to base 1\n worksheet.rowCount,\n columns,\n totalOperation.startsWith(\"MATH\"),\n );\n\n return formula ? { formula: formula, type: ValueType.Formula } : \" \";\n });\n const footerRow = worksheet.addRow(footerRowData);\n\n // Format excel footer cells\n footerRow.font = { bold: true };\n footerRow.alignment = { horizontal: \"right\" };\n columns.map((column, index) => {\n const exceljsCell = footerRow.getCell(index + 1); // Convert base 0 index to base 1\n exceljsCell.fill = footerStyleFill;\n\n if (\n column.obj &&\n objectsIsDate(column.obj) &&\n (exceljsCell.formula?.startsWith(allowedTotals.Min) ||\n exceljsCell.formula?.startsWith(allowedTotals.Max))\n ) {\n const dateFormat =\n webupManagerData.datesLocale === \"it\" ? \"dd/mm/yyyy\" : \"mm/dd/yyyy\";\n exceljsCell.numFmt = dateFormat;\n return;\n }\n\n exceljsCell.numFmt = getExcelNumFormatForGroupedRow(column, totals);\n });\n};\n\nexport const getExcelColumnLetter = (index: number): string => {\n let columnLetter = \"\";\n while (index > 0) {\n index--; // Excel columns are 1-based, but calculations work better with 0-based\n columnLetter = String.fromCharCode((index % 26) + 65) + columnLetter;\n index = Math.floor(index / 26);\n }\n return columnLetter;\n};\n\n/**\n * Returns the formula used in the footer to add Totals at the end of the table\n * @param totalOperation string\n * @param colIndex string\n * @param rowNumber number\n * @returns\n */\nexport const getTotalFormula = (\n worksheet: ExcelJS.Worksheet,\n totalOperation: string,\n colIndex: number,\n rowNumber: number,\n filteredColumns: SmeupDataColumn[],\n isSmeupFormula: boolean,\n): string => {\n const startRow = 2;\n const columnExcelLetter = getExcelColumnLetter(colIndex);\n\n if (isSmeupFormula) {\n return smeupFormulaToExcelFormula(\n totalOperation,\n rowNumber,\n filteredColumns,\n );\n }\n\n if (!allowedTotals[totalOperation]) {\n console.warn(\n `Total operation [' ${totalOperation} '] is not supported`,\n \"exportUtils.ts\",\n );\n return \"\";\n }\n\n if (totalOperation === \"Distinct\") {\n return getDistinctCount(\n `${columnExcelLetter}${startRow}:${columnExcelLetter}${rowNumber}`,\n worksheet,\n );\n } else {\n return `${allowedTotals[totalOperation]}${columnExcelLetter}${startRow}:${columnExcelLetter}${rowNumber})`;\n }\n};\n\nexport const smeupFormulaToExcelFormula = (\n formula: string,\n rowNumber: number,\n filteredColumns: SmeupDataColumn[],\n): string => {\n const result = formula\n .replace(\"MATH\", \"\")\n .replace(/\\[([^\\]]+)\\]/g, (_, key) => {\n const columnIndex =\n filteredColumns.findIndex(col => col.name === key) + 1;\n const columnLetter = getExcelColumnLetter(columnIndex);\n return columnLetter && columnIndex\n ? `${columnLetter}${rowNumber + 1}`\n : key;\n })\n .replaceAll(\",\", \".\"); // Replace eventual , to . => The excel accepted decimal separator\n return result;\n};\n\nexport const smeupFormulaToExcelValue = (\n column: SmeupDataColumn,\n filteredColumns: SmeupDataColumn[],\n cells: Record<string, SmeupDataCell>,\n): string => {\n let resultValue: string | number = \"\";\n if (!column.formula) {\n return \"\";\n }\n const result = column.formula\n .replace(\"MATH\", \"\")\n .replace(/\\[([^\\]]+)\\]/g, (match, key) => {\n const columnIndex = filteredColumns.findIndex(col => col.name === key);\n return columnIndex >= 0\n ? (cells[key]?.value ?? \"\")\n : match === \"[SUM]\"\n ? match\n : key;\n });\n try {\n if (result === \"[SUM]\") {\n resultValue = applySUMFormula(column, filteredColumns, cells);\n } else {\n resultValue = calculateExpression(result);\n }\n } catch {\n resultValue = result; // If the formula fails, return the original formula\n }\n return resultValue.toString();\n};\n\nconst applySUMFormula = (\n column: SmeupDataColumn,\n filteredColumns: SmeupDataColumn[],\n cells: Record<string, SmeupDataCell>,\n): number => {\n let resultValue: number = 0;\n resultValue = 0;\n const index = filteredColumns.findIndex(col => col.name === column.name);\n filteredColumns.slice(0, index).forEach(col => {\n if (col.obj && col.obj.t === \"NR\") {\n let cellValue = 0;\n if (col.formula) {\n cellValue = Number(\n smeupFormulaToExcelValue(col, filteredColumns, cells),\n );\n } else {\n cellValue = Number(cells[col.name]?.value);\n }\n if (!isNaN(cellValue)) {\n resultValue = (resultValue as number) + cellValue;\n }\n }\n });\n return resultValue;\n};\n\nexport const getDistinctCount = (\n range: string,\n worksheet: ExcelJS.Worksheet,\n): string => {\n const column = range.split(\":\")[0].replace(/[0-9]/g, \"\"); // Extract column letter\n const startRow = parseInt(range.split(\":\")[0].replace(/\\D/g, \"\"), 10);\n const endRow = parseInt(range.split(\":\")[1].replace(/\\D/g, \"\"), 10);\n\n // Create a set to store unique values\n const uniqueValues = new Set<string>();\n\n for (let rowIndex = startRow; rowIndex <= endRow; rowIndex++) {\n const cell = worksheet.getCell(`${column}${rowIndex}`);\n if (cell.formula) continue;\n const cellValue = cell.value;\n if (cellValue !== null && cellValue !== undefined) {\n uniqueValues.add(cellValue.toString());\n }\n }\n\n return uniqueValues.size.toString();\n};\n\n/**\n * Estrae tutte le celle (ExcelJS.Cell) da un intervallo rettangolare specificato in un worksheet ExcelJS.\n *\n * L'intervallo è definito dai riferimenti di cella iniziale e finale (es. \"A1\" a \"C3\").\n * Restituisce le celle in ordine riga-major.\n *\n * @param worksheet - Il worksheet ExcelJS da cui estrarre le celle.\n * @param startRef - Il riferimento della cella iniziale (es. \"A1\").\n * @param endRef - Il riferimento della cella finale (es. \"C3\").\n * @returns Un array di ExcelJS.Cell dall'intervallo specificato, in ordine riga-major.\n */\nexport const getCellsFromRange = (\n worksheet: ExcelJS.Worksheet,\n startRef: string,\n endRef: string,\n): ExcelJS.Cell[] => {\n const parseCellRef = (ref: string) => {\n const match = ref.match(/^([A-Z]+)(\\d+)$/i);\n if (!match) return null;\n const col = match[1].toUpperCase();\n const row = parseInt(match[2], 10);\n return { col, row };\n };\n const colToIndex = (col: string) => {\n let idx = 0;\n for (let i = 0; i < col.length; i++) {\n idx = idx * 26 + (col.charCodeAt(i) - 64);\n }\n return idx;\n };\n const start = parseCellRef(startRef);\n const end = parseCellRef(endRef);\n if (!start || !end) return [];\n const cells: ExcelJS.Cell[] = [];\n for (let r = start.row; r <= end.row; r++) {\n for (let c = colToIndex(start.col); c <= colToIndex(end.col); c++) {\n const cell = worksheet.getRow(r).getCell(c);\n cells.push(cell);\n }\n }\n return cells;\n};\n\nexport const groupedCellFormatAttributes = {\n font: { bold: true },\n alignment: { horizontal: \"left\" } as Partial<Alignment>,\n fill: {\n type: \"pattern\",\n pattern: \"solid\",\n fgColor: { argb: \"ffe0e0e0\" },\n } as Fill,\n};\n\nexport const isGroupedCell = (cell: ExcelJS.Cell): boolean => {\n return (\n JSON.stringify({\n font: cell.font,\n alignment: cell.alignment,\n fill: cell.fill,\n }) === JSON.stringify(groupedCellFormatAttributes)\n );\n};\n\n"]}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.footerStyleFill = exports.allowedTotals = exports.exportTypeSupportsFormatting = exports.headerStyleFill = void 0;
|
|
4
|
+
const index_1 = require("../../types/index");
|
|
5
|
+
exports.headerStyleFill = {
|
|
3
6
|
type: "pattern",
|
|
4
7
|
pattern: "solid",
|
|
5
8
|
fgColor: { argb: "E0E0E0" },
|
|
6
9
|
};
|
|
7
|
-
|
|
8
|
-
[SupportedExportFormats.XLSX]: true,
|
|
9
|
-
[SupportedExportFormats.CSV]: false,
|
|
10
|
-
[SupportedExportFormats.TXT]: false,
|
|
11
|
-
[SupportedExportFormats.FILE]: false,
|
|
12
|
-
[SupportedExportFormats.PDF_SCHEDA]: false,
|
|
13
|
-
[SupportedExportFormats.PDF]: false,
|
|
10
|
+
exports.exportTypeSupportsFormatting = {
|
|
11
|
+
[index_1.SupportedExportFormats.XLSX]: true,
|
|
12
|
+
[index_1.SupportedExportFormats.CSV]: false,
|
|
13
|
+
[index_1.SupportedExportFormats.TXT]: false,
|
|
14
|
+
[index_1.SupportedExportFormats.FILE]: false,
|
|
15
|
+
[index_1.SupportedExportFormats.PDF_SCHEDA]: false,
|
|
16
|
+
[index_1.SupportedExportFormats.PDF]: false,
|
|
14
17
|
};
|
|
15
|
-
|
|
18
|
+
exports.allowedTotals = {
|
|
16
19
|
// The different initial number indicates the specific subtotal action
|
|
17
20
|
["Count"]: "SUBTOTAL(3,", // COUNTA
|
|
18
21
|
["Sum"]: "SUBTOTAL(9,", // SUM
|
|
@@ -21,7 +24,7 @@ export const allowedTotals = {
|
|
|
21
24
|
["Average"]: "SUBTOTAL(1,", // AVERAGE
|
|
22
25
|
["Distinct"]: "COUNTA(UNIQUE(", // It is computed in JavaScript, when the Excel is localized in italian, it does not work
|
|
23
26
|
};
|
|
24
|
-
|
|
27
|
+
exports.footerStyleFill = {
|
|
25
28
|
type: "pattern",
|
|
26
29
|
pattern: "solid",
|
|
27
30
|
fgColor: { argb: "EEEEEE" },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"excel-converter.types.js","sourceRoot":"","sources":["../../../src/converters/excel/excel-converter.types.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"excel-converter.types.js","sourceRoot":"","sources":["../../../src/converters/excel/excel-converter.types.ts"],"names":[],"mappings":";;;AACA,6CAA2D;AAY9C,QAAA,eAAe,GAAS;IACnC,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;CAC5B,CAAC;AAEW,QAAA,4BAA4B,GAAG;IAC1C,CAAC,8BAAsB,CAAC,IAAI,CAAC,EAAE,IAAI;IACnC,CAAC,8BAAsB,CAAC,GAAG,CAAC,EAAE,KAAK;IACnC,CAAC,8BAAsB,CAAC,GAAG,CAAC,EAAE,KAAK;IACnC,CAAC,8BAAsB,CAAC,IAAI,CAAC,EAAE,KAAK;IACpC,CAAC,8BAAsB,CAAC,UAAU,CAAC,EAAE,KAAK;IAC1C,CAAC,8BAAsB,CAAC,GAAG,CAAC,EAAE,KAAK;CACpC,CAAC;AAEW,QAAA,aAAa,GAAG;IAC3B,sEAAsE;IACtE,CAAC,OAAoB,CAAC,EAAE,aAAa,EAAE,SAAS;IAChD,CAAC,KAAkB,CAAC,EAAE,aAAa,EAAE,MAAM;IAC3C,CAAC,KAAkB,CAAC,EAAE,aAAa,EAAE,MAAM;IAC3C,CAAC,KAAkB,CAAC,EAAE,aAAa,EAAE,MAAM;IAC3C,CAAC,SAAsB,CAAC,EAAE,aAAa,EAAE,UAAU;IACnD,CAAC,UAAuB,CAAC,EAAE,gBAAgB,EAAE,yFAAyF;CACvI,CAAC;AAEW,QAAA,eAAe,GAAS;IACnC,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;CAC5B,CAAC","sourcesContent":["import { Fill } from \"exceljs\";\nimport { SupportedExportFormats } from \"../../types/index\";\n\nexport declare enum TotalMode {\n COUNT = \"Count\",\n SUM = \"Sum\",\n MIN = \"Min\",\n MAX = \"Max\",\n DISTINCT = \"Distinct\",\n AVERAGE = \"Average\",\n MATH = \"MATH\",\n}\n\nexport const headerStyleFill: Fill = {\n type: \"pattern\",\n pattern: \"solid\",\n fgColor: { argb: \"E0E0E0\" },\n};\n\nexport const exportTypeSupportsFormatting = {\n [SupportedExportFormats.XLSX]: true,\n [SupportedExportFormats.CSV]: false,\n [SupportedExportFormats.TXT]: false,\n [SupportedExportFormats.FILE]: false,\n [SupportedExportFormats.PDF_SCHEDA]: false,\n [SupportedExportFormats.PDF]: false,\n};\n\nexport const allowedTotals = {\n // The different initial number indicates the specific subtotal action\n [\"Count\" as TotalMode]: \"SUBTOTAL(3,\", // COUNTA\n [\"Sum\" as TotalMode]: \"SUBTOTAL(9,\", // SUM\n [\"Max\" as TotalMode]: \"SUBTOTAL(4,\", // MAX\n [\"Min\" as TotalMode]: \"SUBTOTAL(5,\", // MIN\n [\"Average\" as TotalMode]: \"SUBTOTAL(1,\", // AVERAGE\n [\"Distinct\" as TotalMode]: \"COUNTA(UNIQUE(\", // It is computed in JavaScript, when the Excel is localized in italian, it does not work\n};\n\nexport const footerStyleFill: Fill = {\n type: \"pattern\",\n pattern: \"solid\",\n fgColor: { argb: \"EEEEEE\" },\n};\n\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ExcelJS from "exceljs";
|
|
2
|
-
import { GenericObject, WebupManagerData, SupportedExportFormats } from "../../types/index
|
|
3
|
-
import { SmeupDataColumn, SmeupDataRow, SmeupDataTable } from "../../types/data-structures/smeupDataTable
|
|
4
|
-
import { SmeupDataNode } from "../../types/data-structures/smeupDataTree
|
|
2
|
+
import { GenericObject, WebupManagerData, SupportedExportFormats } from "../../types/index";
|
|
3
|
+
import { SmeupDataColumn, SmeupDataRow, SmeupDataTable } from "../../types/data-structures/smeupDataTable";
|
|
4
|
+
import { SmeupDataNode } from "../../types/data-structures/smeupDataTree";
|
|
5
5
|
export declare const dataTableToExcelWorkbook: (component: {
|
|
6
6
|
smeupDataTable: SmeupDataTable;
|
|
7
7
|
props: GenericObject;
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getExcelNumFormat = exports.getExcelNumFormatForGroupedRow = exports.addStyleToExceljsRow = exports.dataTableToExcelWorkbook = void 0;
|
|
7
|
+
const exceljs_1 = __importDefault(require("exceljs"));
|
|
8
|
+
const commons_utility_1 = require("../../utils/commons-utility");
|
|
9
|
+
const excel_converter_types_1 = require("./excel-converter.types");
|
|
10
|
+
const datastructure_utility_1 = require("../../utils/datastructure-utility");
|
|
11
|
+
const commons_1 = require("./commons");
|
|
12
|
+
const dataTableToExcelWorkbook = (component, fileFormat, webupManagerData) => {
|
|
7
13
|
// Create a new ExcelJS.Workbook and return it as a resolved Promise
|
|
8
14
|
const { smeupDataTable: smeupDataTable, props } = component;
|
|
9
|
-
const workbook = new
|
|
10
|
-
const worksheet = initializeWorksheet(workbook);
|
|
15
|
+
const workbook = new exceljs_1.default.Workbook();
|
|
16
|
+
const worksheet = (0, commons_1.initializeWorksheet)(workbook);
|
|
11
17
|
const groupsArray = Array.isArray(props?.groups)
|
|
12
18
|
? props.groups
|
|
13
19
|
: [];
|
|
14
20
|
// Visible attribute is used only to determine if the column is visible,
|
|
15
21
|
// ant not to determine if the group is active
|
|
16
22
|
const activeGroups = groupsArray.map((group) => group.column);
|
|
17
|
-
const filteredColumns = getFilteredColumns(smeupDataTable.columns, props, groupsArray);
|
|
23
|
+
const filteredColumns = (0, commons_utility_1.getFilteredColumns)(smeupDataTable.columns, props, groupsArray);
|
|
18
24
|
const maxColumnValueLenght = {};
|
|
19
25
|
let rowNumber = 1; // Start row number
|
|
20
26
|
// Headers setup
|
|
21
27
|
setDataTableHeaderRow(worksheet, filteredColumns, maxColumnValueLenght);
|
|
22
28
|
// Filter and sort rows (if filters are available)
|
|
23
|
-
const rows = filterRows(smeupDataTable, filteredColumns, props?.filters);
|
|
29
|
+
const rows = (0, commons_utility_1.filterRows)(smeupDataTable, filteredColumns, props?.filters);
|
|
24
30
|
if (activeGroups?.length > 0) {
|
|
25
|
-
sortRows(rows, component.props.sort, activeGroups);
|
|
31
|
+
(0, commons_utility_1.sortRows)(rows, component.props.sort, activeGroups);
|
|
26
32
|
// Recursive grouping
|
|
27
33
|
rowNumber = insertDataTableGroupedRows(worksheet, rows, activeGroups, filteredColumns, smeupDataTable.columns, rowNumber, fileFormat, webupManagerData, 1, maxColumnValueLenght, (props?.totals ?? {}));
|
|
28
34
|
//INTERACTIVE GROUPS MANAGING
|
|
@@ -36,12 +42,12 @@ export const dataTableToExcelWorkbook = (component, fileFormat, webupManagerData
|
|
|
36
42
|
};
|
|
37
43
|
}
|
|
38
44
|
else {
|
|
39
|
-
sortRows(rows, component.props.sort);
|
|
45
|
+
(0, commons_utility_1.sortRows)(rows, component.props.sort);
|
|
40
46
|
// Process rows normally if no grouping
|
|
41
47
|
rowNumber = insertDataTableRows(worksheet, rows, filteredColumns, rowNumber, fileFormat, webupManagerData, maxColumnValueLenght);
|
|
42
48
|
}
|
|
43
|
-
if (exportTypeSupportsFormatting[fileFormat] && props?.totals) {
|
|
44
|
-
addFooterTotalsRow(worksheet, filteredColumns, props, webupManagerData);
|
|
49
|
+
if (excel_converter_types_1.exportTypeSupportsFormatting[fileFormat] && props?.totals) {
|
|
50
|
+
(0, commons_1.addFooterTotalsRow)(worksheet, filteredColumns, props, webupManagerData);
|
|
45
51
|
}
|
|
46
52
|
// Apply column width
|
|
47
53
|
worksheet.columns.forEach(col => {
|
|
@@ -65,6 +71,7 @@ export const dataTableToExcelWorkbook = (component, fileFormat, webupManagerData
|
|
|
65
71
|
};
|
|
66
72
|
return workbook;
|
|
67
73
|
};
|
|
74
|
+
exports.dataTableToExcelWorkbook = dataTableToExcelWorkbook;
|
|
68
75
|
/**
|
|
69
76
|
* Creates the first row of the table by looking at dataTable columns.
|
|
70
77
|
* Also updates column width calculations
|
|
@@ -74,15 +81,15 @@ export const dataTableToExcelWorkbook = (component, fileFormat, webupManagerData
|
|
|
74
81
|
*/
|
|
75
82
|
const setDataTableHeaderRow = (worksheet, filteredColumns, maxValueLengthMap) => {
|
|
76
83
|
worksheet.columns = filteredColumns.map(col => {
|
|
77
|
-
updateMaxValueLength(maxValueLengthMap, col.title, col.name);
|
|
84
|
+
(0, commons_utility_1.updateMaxValueLength)(maxValueLengthMap, col.title, col.name);
|
|
78
85
|
return {
|
|
79
86
|
header: col.title,
|
|
80
87
|
key: col.name,
|
|
81
88
|
width: maxValueLengthMap[col.name], // Set the width to the updated value
|
|
82
|
-
hidden: isColumnHidden(col),
|
|
89
|
+
hidden: (0, datastructure_utility_1.isColumnHidden)(col),
|
|
83
90
|
};
|
|
84
91
|
});
|
|
85
|
-
setHeaderStyling(worksheet);
|
|
92
|
+
(0, commons_1.setHeaderStyling)(worksheet);
|
|
86
93
|
};
|
|
87
94
|
const insertDataTableGroupedRows = (worksheet, rows, groups, filteredColumns, unfilteredColumns, rowNumber, fileFormat, webupManagerData, currentOutlineLevel = 1, maxColumnValueLength, totals) => {
|
|
88
95
|
if (!groups.length) {
|
|
@@ -109,7 +116,7 @@ const insertDataTableGroupedRows = (worksheet, rows, groups, filteredColumns, un
|
|
|
109
116
|
// Compute totals and format cells
|
|
110
117
|
for (const [colIndex, col] of filteredColumns.entries()) {
|
|
111
118
|
const cell = headerRow.getCell(colIndex + 1);
|
|
112
|
-
cell.numFmt = getExcelNumFormatForGroupedRow(col, totals);
|
|
119
|
+
cell.numFmt = (0, exports.getExcelNumFormatForGroupedRow)(col, totals);
|
|
113
120
|
decorateHeaderRow(cell);
|
|
114
121
|
if (!totals)
|
|
115
122
|
continue;
|
|
@@ -118,7 +125,7 @@ const insertDataTableGroupedRows = (worksheet, rows, groups, filteredColumns, un
|
|
|
118
125
|
cell.alignment = { horizontal: "right" };
|
|
119
126
|
cell.value = totalFormula.startsWith("MATH")
|
|
120
127
|
? {
|
|
121
|
-
formula: smeupFormulaToExcelFormula(totalFormula.replace("MATH", ""), headerRowNumber - 1, filteredColumns),
|
|
128
|
+
formula: (0, commons_1.smeupFormulaToExcelFormula)(totalFormula.replace("MATH", ""), headerRowNumber - 1, filteredColumns),
|
|
122
129
|
}
|
|
123
130
|
: {
|
|
124
131
|
formula: getSubGroupTotalFormula(worksheet, totalFormula, colIndex + 1, headerRowNumber + 1, lastDataRow),
|
|
@@ -135,20 +142,20 @@ const insertDataTableRows = (worksheet, rows, filteredColumns, rowNumber, fileFo
|
|
|
135
142
|
for (const row of rows) {
|
|
136
143
|
const rowData = filteredColumns.map(column => {
|
|
137
144
|
const cell = (row?.cells ?? {})[column.name];
|
|
138
|
-
updateMaxValueLength(maxColumnValueLenght, cell?.value, column.name);
|
|
145
|
+
(0, commons_utility_1.updateMaxValueLength)(maxColumnValueLenght, cell?.value, column.name);
|
|
139
146
|
return column.formula
|
|
140
|
-
? calculateValue(smeupFormulaToExcelValue(column, filteredColumns, row?.cells ?? {}), cell.obj ?? { t: "", p: "", k: "" }, fileFormat, webupManagerData)
|
|
141
|
-
: calculateCellValue(cell, fileFormat, webupManagerData);
|
|
147
|
+
? (0, commons_utility_1.calculateValue)((0, commons_1.smeupFormulaToExcelValue)(column, filteredColumns, row?.cells ?? {}), cell.obj ?? { t: "", p: "", k: "" }, fileFormat, webupManagerData)
|
|
148
|
+
: (0, commons_utility_1.calculateCellValue)(cell, fileFormat, webupManagerData);
|
|
142
149
|
});
|
|
143
150
|
const newRow = worksheet.addRow(rowData);
|
|
144
|
-
if (exportTypeSupportsFormatting[fileFormat]) {
|
|
145
|
-
addStyleToExceljsRow(newRow, filteredColumns, row);
|
|
151
|
+
if (excel_converter_types_1.exportTypeSupportsFormatting[fileFormat]) {
|
|
152
|
+
(0, exports.addStyleToExceljsRow)(newRow, filteredColumns, row);
|
|
146
153
|
}
|
|
147
154
|
rowNumber++;
|
|
148
155
|
}
|
|
149
156
|
return rowNumber;
|
|
150
157
|
};
|
|
151
|
-
|
|
158
|
+
const addStyleToExceljsRow = (exceljsRow, columns, row) => {
|
|
152
159
|
exceljsRow.eachCell((cell, cellIndex) => {
|
|
153
160
|
const columnIndex = cellIndex - 1;
|
|
154
161
|
const columnName = columns[columnIndex]?.name;
|
|
@@ -167,9 +174,10 @@ export const addStyleToExceljsRow = (exceljsRow, columns, row) => {
|
|
|
167
174
|
}
|
|
168
175
|
});
|
|
169
176
|
};
|
|
177
|
+
exports.addStyleToExceljsRow = addStyleToExceljsRow;
|
|
170
178
|
const applyDefaultXlsxCellStyle = (cell, xlsxCell) => {
|
|
171
179
|
if (typeof xlsxCell.value === "number" || xlsxCell.formula) {
|
|
172
|
-
xlsxCell.numFmt = getExcelNumFormat(cell.data?.decimals ?? 0, cell.data?.integers ?? 0);
|
|
180
|
+
xlsxCell.numFmt = (0, exports.getExcelNumFormat)(cell.data?.decimals ?? 0, cell.data?.integers ?? 0);
|
|
173
181
|
}
|
|
174
182
|
};
|
|
175
183
|
/**
|
|
@@ -192,7 +200,7 @@ const cellToXlsxStyleConverter = (cell, xlsxCell, optionalRowStyles) => {
|
|
|
192
200
|
xlsxCell.fill = {
|
|
193
201
|
type: "pattern",
|
|
194
202
|
pattern: "solid",
|
|
195
|
-
fgColor: { argb: hexToArgb(cellStyle.backgroundColor) },
|
|
203
|
+
fgColor: { argb: (0, commons_utility_1.hexToArgb)(cellStyle.backgroundColor) },
|
|
196
204
|
};
|
|
197
205
|
}
|
|
198
206
|
if (cellStyle.fontWeight == "bold") {
|
|
@@ -204,20 +212,21 @@ const cellToXlsxStyleConverter = (cell, xlsxCell, optionalRowStyles) => {
|
|
|
204
212
|
if (cellStyle.color) {
|
|
205
213
|
xlsxCell.font = {
|
|
206
214
|
...xlsxCell.font,
|
|
207
|
-
color: { argb: hexToArgb(cellStyle.color) },
|
|
215
|
+
color: { argb: (0, commons_utility_1.hexToArgb)(cellStyle.color) },
|
|
208
216
|
};
|
|
209
217
|
}
|
|
210
218
|
};
|
|
211
|
-
|
|
219
|
+
const getExcelNumFormatForGroupedRow = (column, totals) => {
|
|
212
220
|
const totalOperation = totals?.[column.name];
|
|
213
221
|
if (totalOperation === "Distinct") {
|
|
214
222
|
return "0"; // Distinct count does not require decimals
|
|
215
223
|
}
|
|
216
224
|
else {
|
|
217
|
-
return getExcelNumFormat(column.decimals ?? 0, column.integers ?? 0);
|
|
225
|
+
return (0, exports.getExcelNumFormat)(column.decimals ?? 0, column.integers ?? 0);
|
|
218
226
|
}
|
|
219
227
|
};
|
|
220
|
-
|
|
228
|
+
exports.getExcelNumFormatForGroupedRow = getExcelNumFormatForGroupedRow;
|
|
229
|
+
const getExcelNumFormat = (cellDecimals, cellIntegers) => {
|
|
221
230
|
// Step 1: Build the integer part with necessary '#' and '0'
|
|
222
231
|
let integerPart = cellIntegers ? "#".repeat(cellIntegers - 1) + "0" : "0";
|
|
223
232
|
// Step 2: Insert commas every three digits from the right
|
|
@@ -236,20 +245,21 @@ export const getExcelNumFormat = (cellDecimals, cellIntegers) => {
|
|
|
236
245
|
numFmt += `;[Red]-${numFmt}`;
|
|
237
246
|
return numFmt;
|
|
238
247
|
};
|
|
248
|
+
exports.getExcelNumFormat = getExcelNumFormat;
|
|
239
249
|
const decorateHeaderRow = (headerCell) => {
|
|
240
|
-
Object.assign(headerCell, groupedCellFormatAttributes);
|
|
250
|
+
Object.assign(headerCell, commons_1.groupedCellFormatAttributes);
|
|
241
251
|
};
|
|
242
252
|
const getSubGroupTotalFormula = (worksheet, totalOperation, colIndex, firstDataRow, lastDataRow) => {
|
|
243
|
-
const columnExcelLetter = getExcelColumnLetter(colIndex);
|
|
244
|
-
if (!allowedTotals[totalOperation]) {
|
|
253
|
+
const columnExcelLetter = (0, commons_1.getExcelColumnLetter)(colIndex);
|
|
254
|
+
if (!excel_converter_types_1.allowedTotals[totalOperation]) {
|
|
245
255
|
console.warn(`Total operation [' ${totalOperation} '] is not supported`, "exportUtils.ts");
|
|
246
256
|
return "";
|
|
247
257
|
}
|
|
248
258
|
if (totalOperation === "Distinct") {
|
|
249
|
-
return getDistinctCount(`${columnExcelLetter}${firstDataRow}:${columnExcelLetter}${lastDataRow}`, worksheet);
|
|
259
|
+
return (0, commons_1.getDistinctCount)(`${columnExcelLetter}${firstDataRow}:${columnExcelLetter}${lastDataRow}`, worksheet);
|
|
250
260
|
}
|
|
251
261
|
else {
|
|
252
|
-
return `${allowedTotals[totalOperation]}${columnExcelLetter}${firstDataRow}:${columnExcelLetter}${lastDataRow})`;
|
|
262
|
+
return `${excel_converter_types_1.allowedTotals[totalOperation]}${columnExcelLetter}${firstDataRow}:${columnExcelLetter}${lastDataRow})`;
|
|
253
263
|
}
|
|
254
264
|
};
|
|
255
265
|
const ensureGroupRowHasDescription = (worksheet) => {
|