@sme.up/doc-alchemist 1.2.0-SNAPSHOT-20250627103210 → 1.2.0-SNAPSHOT-20250704074443
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 +280 -28
- package/dist/assets/gfx-data.d.ts +1 -0
- package/dist/assets/gfx-data.js +2 -0
- package/dist/assets/gfx-data.js.map +1 -0
- package/dist/{excel → converters/excel}/commons.d.ts +15 -2
- package/dist/{excel → converters/excel}/commons.js +97 -23
- package/dist/converters/excel/commons.js.map +1 -0
- package/dist/{excel/excel-generator.types.d.ts → converters/excel/excel-converter.types.d.ts} +1 -0
- package/dist/{excel/excel-generator.types.js → converters/excel/excel-converter.types.js} +3 -2
- package/dist/converters/excel/excel-converter.types.js.map +1 -0
- package/dist/{excel/matrix-generator.d.ts → converters/excel/matrix-converter.d.ts} +3 -3
- package/dist/{excel/matrix-generator.js → converters/excel/matrix-converter.js} +15 -13
- package/dist/converters/excel/matrix-converter.js.map +1 -0
- package/dist/{excel/tree-generator.d.ts → converters/excel/tree-converter.d.ts} +2 -2
- package/dist/{excel/tree-generator.js → converters/excel/tree-converter.js} +5 -5
- package/dist/converters/excel/tree-converter.js.map +1 -0
- package/dist/{excel/excel-generator.js → converters/excel-converter.js} +4 -4
- package/dist/converters/excel-converter.js.map +1 -0
- package/dist/{images → converters/images}/charts-generator.d.ts +2 -2
- package/dist/converters/images/charts-generator.js.map +1 -0
- package/dist/converters/pdf/autotable-renderer.d.ts +3 -0
- package/dist/converters/pdf/autotable-renderer.js +89 -0
- package/dist/converters/pdf/autotable-renderer.js.map +1 -0
- package/dist/converters/pdf/cover-renderer.d.ts +1 -0
- package/dist/converters/pdf/cover-renderer.js +26 -0
- package/dist/converters/pdf/cover-renderer.js.map +1 -0
- package/dist/converters/pdf/formulas-helper.d.ts +40 -0
- package/dist/converters/pdf/formulas-helper.js +227 -0
- package/dist/converters/pdf/formulas-helper.js.map +1 -0
- package/dist/converters/pdf/matrix-converter.d.ts +16 -0
- package/dist/converters/pdf/matrix-converter.js +198 -0
- package/dist/converters/pdf/matrix-converter.js.map +1 -0
- package/dist/converters/pdf/pdf-converter.types.d.ts +12 -0
- package/dist/converters/pdf/pdf-converter.types.js +2 -0
- package/dist/converters/pdf/pdf-converter.types.js.map +1 -0
- package/dist/{pdf/sch-generator.d.ts → converters/pdf/sch-converter.d.ts} +1 -1
- package/dist/{pdf/sch-generator.js → converters/pdf/sch-converter.js} +2 -2
- package/dist/converters/pdf/sch-converter.js.map +1 -0
- package/dist/{pdf/pdf-generator.d.ts → converters/pdf-converter.d.ts} +3 -3
- package/dist/converters/pdf-converter.js +44 -0
- package/dist/converters/pdf-converter.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/{generator-utility.d.ts → commons-utility.d.ts} +26 -1
- package/dist/utils/{generator-utility.js → commons-utility.js} +63 -10
- package/dist/utils/commons-utility.js.map +1 -0
- package/dist/utils/datastructure-utility.js +2 -2
- package/dist/utils/datastructure-utility.js.map +1 -1
- package/dist/utils/dates-utility.d.ts +9 -0
- package/dist/utils/dates-utility.js +18 -0
- package/dist/utils/dates-utility.js.map +1 -1
- package/dist/utils/formatter-utility.d.ts +3 -0
- package/dist/utils/formatter-utility.js +36 -0
- package/dist/utils/formatter-utility.js.map +1 -0
- package/dist/utils/math-utility.d.ts +1 -0
- package/dist/utils/math-utility.js +9 -0
- package/dist/utils/math-utility.js.map +1 -1
- package/package.json +4 -2
- package/dist/excel/commons.js.map +0 -1
- package/dist/excel/excel-generator.js.map +0 -1
- package/dist/excel/excel-generator.types.js.map +0 -1
- package/dist/excel/matrix-generator.js.map +0 -1
- package/dist/excel/tree-generator.js.map +0 -1
- package/dist/images/charts-generator.js.map +0 -1
- package/dist/pdf/pdf-generator.js +0 -9
- package/dist/pdf/pdf-generator.js.map +0 -1
- package/dist/pdf/sch-generator.js.map +0 -1
- package/dist/utils/generator-utility.js.map +0 -1
- /package/dist/{excel/excel-generator.d.ts → converters/excel-converter.d.ts} +0 -0
- /package/dist/{images → converters/images}/charts-generator.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SmeupDataTable } from "../../types/data-structures/smeupDataTable.js";
|
|
2
|
+
import { ChartOptions } from "../../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Converts SmeupDataTable to chart image buffer
|
|
5
5
|
* @param dataTable - SmeupDataTable containing the data
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charts-generator.js","sourceRoot":"","sources":["../../../src/converters/images/charts-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAKnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,SAAyB,EACzB,SAAiB,EACjB,YAA0B,EACT,EAAE;IACnB,mDAAmD;IACnD,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IAE7C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,mBAAmB,CAAC,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IACvE,CAAC;SAAM,CAAC;QACN,OAAO,sBAAsB,CAAC,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IACpE,CAAC;AACH,CAAC,CAAC;AAEF;;GAEG;AACH,KAAK,UAAU,mBAAmB,CAChC,SAAyB,EACzB,SAAiB,EACjB,YAA0B;IAE1B,IAAI,CAAC;QACH,oCAAoC;QACpC,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;QAEhD,MAAM,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,MAAM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OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,SAAiB;IAC3C,MAAM,IAAI,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IACrC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK,CAAC;QACX,KAAK,QAAQ;YACX,OAAO,KAAK,CAAC;QACf,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,KAAK;YACR,OAAO,KAAK,CAAC;QACf,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,CAAC,IAAI,CAAC,uBAAuB,SAAS,qBAAqB,CAAC,CAAC;YACpE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC","sourcesContent":["import * as echarts from \"echarts\";\nimport type { EChartsOption } from \"echarts\";\nimport { SmeupDataTable } from \"../../types/data-structures/smeupDataTable.js\";\nimport { ChartOptions } from \"../../types/index.js\";\n\n/**\n * Converts SmeupDataTable to chart image buffer\n * @param dataTable - SmeupDataTable containing the data\n * @param chartType - Type of chart (bar, line, pie, scatter)\n * @returns Promise<Buffer> containing the chart image\n */\nexport const dataTableToChart = async (\n dataTable: SmeupDataTable,\n chartType: string,\n chartOptions: ChartOptions,\n): Promise<Buffer> => {\n // Check if we're in Node.js or browser environment\n const isNode = typeof window === \"undefined\";\n\n if (isNode) {\n return await generateChartInNode(dataTable, chartType, chartOptions);\n } else {\n return generateChartInBrowser(dataTable, chartType, chartOptions);\n }\n};\n\n/**\n * Generate chart in Node.js environment using canvas\n */\nasync function generateChartInNode(\n dataTable: SmeupDataTable,\n chartType: string,\n chartOptions: ChartOptions,\n): Promise<Buffer> {\n try {\n // Dynamic import for Node.js canvas\n const { createCanvas } = await import(\"canvas\");\n\n const width = Number(chartOptions.Width);\n const height = Number(chartOptions.Height);\n\n // Create canvas\n const canvas = createCanvas(width, height);\n\n // Create a minimal DOM-like environment for ECharts\n const mockElement = {\n clientWidth: width,\n clientHeight: width,\n style: {},\n addEventListener: () => {},\n removeEventListener: () => {},\n getAttribute: () => null,\n setAttribute: () => {},\n getContext: (type: string) => {\n if (type === \"2d\") {\n return canvas.getContext(\"2d\");\n }\n return null;\n },\n appendChild: () => {},\n removeChild: () => {},\n ownerDocument: {\n createElement: (tagName: string) => {\n if (tagName === \"canvas\") {\n return createCanvas(width, height);\n }\n return mockElement;\n },\n createElementNS: () => mockElement,\n defaultView: {\n getComputedStyle: () => ({ getPropertyValue: () => \"\" }),\n },\n },\n };\n\n // Initialize ECharts with the mock element\n const chart = echarts.init(mockElement as unknown as HTMLElement, null, {\n renderer: \"canvas\",\n useDirtyRect: false,\n width: width,\n height: height,\n });\n\n // Convert data table to chart configuration\n const config = convertDataTableToChartConfig(\n dataTable,\n chartType,\n chartOptions,\n );\n\n // Set chart options\n chart.setOption(config as EChartsOption);\n\n // Force render by calling resize\n chart.resize();\n\n // Get image buffer from canvas\n const imageBuffer = canvas.toBuffer(\"image/jpeg\");\n\n // Cleanup\n chart.dispose();\n\n return imageBuffer;\n } catch (error) {\n console.error(\"Error generating chart in Node.js:\", error);\n throw new Error(\n `Failed to generate chart: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n}\n\n/**\n * Generate chart in browser environment\n */\nfunction generateChartInBrowser(\n dataTable: SmeupDataTable,\n chartType: string,\n chartOptions: ChartOptions,\n): Buffer {\n try {\n const width = Number(chartOptions.Width);\n const height = Number(chartOptions.height);\n // Create temporary canvas element\n const canvas = document.createElement(\"canvas\");\n canvas.width = width;\n canvas.height = height;\n canvas.style.position = \"absolute\";\n canvas.style.left = \"-9999px\";\n document.body.appendChild(canvas);\n\n // Initialize ECharts with canvas\n const chart = echarts.init(canvas, null, {\n renderer: \"canvas\",\n useDirtyRect: false,\n width: width,\n height: height,\n });\n\n // Convert data table to chart configuration\n const config = convertDataTableToChartConfig(\n dataTable,\n chartType,\n chartOptions,\n );\n\n // Set chart options\n chart.setOption(config as EChartsOption);\n\n // Get image data\n const imageDataUrl = chart.getDataURL({\n type: \"jpeg\",\n pixelRatio: 1,\n backgroundColor: \"#fff\",\n });\n\n // Convert data URL to buffer\n const base64Data = imageDataUrl.replace(/^data:image\\/jpeg;base64,/, \"\");\n const imageBuffer = Buffer.from(base64Data, \"base64\");\n\n // Cleanup\n chart.dispose();\n document.body.removeChild(canvas);\n\n return imageBuffer;\n } catch (error) {\n console.error(\"Error generating chart in browser:\", error);\n throw new Error(\n `Failed to generate chart: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n}\n\n/**\n * Convert SmeupDataTable to ECharts configuration\n */\nfunction convertDataTableToChartConfig(\n dataTable: SmeupDataTable,\n chartType: string,\n chartOptions: ChartOptions,\n): EChartsOption {\n if (!dataTable.columns || !dataTable.rows || dataTable.rows.length === 0) {\n throw new Error(\"Invalid data table: missing columns or rows\");\n }\n\n // Get visible columns\n const visibleColumns = dataTable.columns.filter(col => col.visible !== false);\n\n if (visibleColumns.length < 2) {\n throw new Error(\n \"Data table must have at least 2 visible columns for chart generation\",\n );\n }\n\n // First column is typically used for categories/labels\n const categoryColumn = visibleColumns[0];\n const seriesColumns = chartOptions.Series?.split(\"|\");\n if (!seriesColumns || seriesColumns.length === 0) {\n throw new Error(\"Chart options must specify at least one series\");\n }\n const dataColumns = seriesColumns\n .map(name => visibleColumns.find(col => col.name === name))\n .filter(\n (column): column is NonNullable<typeof column> => column !== undefined,\n );\n\n if (dataColumns.length === 0) {\n throw new Error(\"No valid data columns found for chart series\");\n }\n\n // Extract categories from first column\n const categories = dataTable.rows.map(\n row => row.cells?.[categoryColumn.name]?.value?.toString() || \"\",\n );\n\n // Extract data series from remaining columns\n const normalizedType = normalizeChartType(chartType);\n const series = dataColumns.map(column => {\n const data = dataTable.rows.map(row => {\n const cellValue = row.cells?.[column.name]?.value;\n return parseFloat(cellValue?.toString() || \"0\") || 0;\n });\n\n const seriesData =\n chartType.toLowerCase() === \"pie\"\n ? data.map((value, index) => ({ value, name: categories[index] }))\n : data;\n\n // Create properly typed series based on chart type\n switch (normalizedType) {\n case \"pie\":\n return {\n name: column.title || column.name,\n type: \"pie\" as const,\n data: seriesData,\n };\n case \"line\":\n return {\n name: column.title || column.name,\n type: \"line\" as const,\n data: seriesData,\n lineStyle: { width: 8 },\n };\n case \"bar\":\n return {\n name: column.title || column.name,\n type: \"bar\" as const,\n data: seriesData,\n };\n case \"scatter\":\n return {\n name: column.title || column.name,\n type: \"scatter\" as const,\n data: seriesData,\n };\n default:\n return {\n name: column.title || column.name,\n type: \"bar\" as const,\n data: seriesData,\n };\n }\n });\n\n // Build chart configuration based on type\n const config: EChartsOption = {\n tooltip: {\n trigger: chartType.toLowerCase() === \"pie\" ? \"item\" : \"axis\",\n },\n series,\n backgroundColor: \"#fff\",\n textStyle: {\n fontSize: 36,\n },\n };\n // Add legend for multiple series or pie charts\n if (series.length > 1 || chartType.toLowerCase() === \"pie\") {\n config.legend = {\n data: series.map(s => s.name),\n textStyle: { fontSize: 32 },\n };\n }\n\n // Add axes for non-pie charts\n if (chartType.toLowerCase() !== \"pie\") {\n config.xAxis = {\n type: \"category\",\n data: categories,\n axisLabel: { fontSize: 32 },\n };\n config.yAxis = {\n type: \"value\",\n axisLabel: { fontSize: 32 },\n };\n }\n\n return config;\n}\n\n/**\n * Normalize chart type to ECharts supported types\n */\nfunction normalizeChartType(chartType: string): string {\n const type = chartType.toLowerCase();\n switch (type) {\n case \"bar\":\n case \"column\":\n return \"bar\";\n case \"line\":\n return \"line\";\n case \"pie\":\n return \"pie\";\n case \"scatter\":\n return \"scatter\";\n default:\n console.warn(`Unknown chart type: ${chartType}, defaulting to bar`);\n return \"bar\";\n }\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { UserOptions } from "jspdf-autotable";
|
|
2
|
+
import { CellStyleData, CellValueProps } from "./pdf-converter.types.js";
|
|
3
|
+
export declare const getAutoTableOptions: (visibleHeaders: string[], data: CellValueProps[][], optimalFontSize: number, cellStyles: CellStyleData[][], logoBase64?: string) => UserOptions;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export const getAutoTableOptions = (visibleHeaders, data, optimalFontSize, cellStyles, logoBase64) => {
|
|
2
|
+
const { styles, columnStyles, headStyles } = getTableStyles(visibleHeaders, optimalFontSize);
|
|
3
|
+
return {
|
|
4
|
+
head: [visibleHeaders],
|
|
5
|
+
body: data.map(row => row.map(cell => cell.text)),
|
|
6
|
+
startY: 25,
|
|
7
|
+
margin: { left: 5, right: 5, top: 25, bottom: 10 },
|
|
8
|
+
styles,
|
|
9
|
+
columnStyles,
|
|
10
|
+
headStyles,
|
|
11
|
+
didDrawPage: dataArg => didDrawPageHandler(dataArg, logoBase64),
|
|
12
|
+
didParseCell: dataArg => didParseCellHandler(dataArg, cellStyles),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const getTableStyles = (visibleHeaders, optimalFontSize) => {
|
|
16
|
+
const styles = {
|
|
17
|
+
font: "helvetica",
|
|
18
|
+
fontSize: optimalFontSize + 1,
|
|
19
|
+
cellPadding: 1,
|
|
20
|
+
overflow: "visible",
|
|
21
|
+
cellWidth: "auto",
|
|
22
|
+
minCellWidth: 5,
|
|
23
|
+
};
|
|
24
|
+
const columnStyles = {
|
|
25
|
+
...Object.fromEntries(visibleHeaders.map((_, index) => [
|
|
26
|
+
index,
|
|
27
|
+
{
|
|
28
|
+
cellWidth: "wrap",
|
|
29
|
+
halign: "left",
|
|
30
|
+
overflow: "visible",
|
|
31
|
+
cellPadding: { top: 1, right: 1, bottom: 1, left: 1 },
|
|
32
|
+
},
|
|
33
|
+
])),
|
|
34
|
+
};
|
|
35
|
+
const headStyles = {
|
|
36
|
+
fillColor: [255, 0, 0],
|
|
37
|
+
textColor: [255, 255, 255],
|
|
38
|
+
fontStyle: "bold",
|
|
39
|
+
halign: "center",
|
|
40
|
+
};
|
|
41
|
+
return { styles, columnStyles, headStyles };
|
|
42
|
+
};
|
|
43
|
+
const didParseCellHandler = (dataArg, cellStyles) => {
|
|
44
|
+
if (dataArg.section === "body") {
|
|
45
|
+
const rowIndex = dataArg.row.index;
|
|
46
|
+
const colIndex = dataArg.column.index;
|
|
47
|
+
const cellStyle = cellStyles[rowIndex]?.[colIndex];
|
|
48
|
+
if (cellStyle) {
|
|
49
|
+
// Apply styles from the Excel cell
|
|
50
|
+
if (cellStyle.fontStyle) {
|
|
51
|
+
dataArg.cell.styles.fontStyle = cellStyle.fontStyle;
|
|
52
|
+
}
|
|
53
|
+
if (cellStyle.textColor) {
|
|
54
|
+
dataArg.cell.styles.textColor = cellStyle.textColor;
|
|
55
|
+
}
|
|
56
|
+
if (cellStyle.fillColor) {
|
|
57
|
+
dataArg.cell.styles.fillColor = cellStyle.fillColor;
|
|
58
|
+
}
|
|
59
|
+
if (cellStyle.halign === "right") {
|
|
60
|
+
dataArg.cell.styles.halign = "right";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const didDrawPageHandler = (dataArg, logoBase64) => {
|
|
66
|
+
// Add the logo on each page
|
|
67
|
+
if (logoBase64) {
|
|
68
|
+
const pageWidth = dataArg.doc.internal.pageSize.getWidth();
|
|
69
|
+
const logoWidth = 40; // Logo width in mm
|
|
70
|
+
const logoHeight = 15; // Logo height in mm
|
|
71
|
+
const logoX = pageWidth - logoWidth - 10; // 10mm from the right margin
|
|
72
|
+
const logoY = 5; // 5mm from the top margin
|
|
73
|
+
// Add the text "Intestazione" aligned to the left margin
|
|
74
|
+
const text = "Intestazione";
|
|
75
|
+
const textFontSize = 14;
|
|
76
|
+
const textX = 5;
|
|
77
|
+
const textY = 10;
|
|
78
|
+
dataArg.doc.setFontSize(textFontSize);
|
|
79
|
+
dataArg.doc.setFont("helvetica", "normal");
|
|
80
|
+
dataArg.doc.text(text, textX, textY, { align: "left" });
|
|
81
|
+
try {
|
|
82
|
+
dataArg.doc.addImage(logoBase64, "PNG", logoX, logoY, logoWidth, logoHeight);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.warn("Error adding logo:", error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=autotable-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autotable-renderer.js","sourceRoot":"","sources":["../../../src/converters/pdf/autotable-renderer.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,cAAwB,EACxB,IAAwB,EACxB,eAAuB,EACvB,UAA6B,EAC7B,UAAmB,EACN,EAAE;IACf,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,cAAc,CACzD,cAAc,EACd,eAAe,CAChB,CAAC;IACF,OAAO;QACL,IAAI,EAAE,CAAC,cAAc,CAAC;QACtB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAClD,MAAM;QACN,YAAY;QACZ,UAAU;QACV,WAAW,EAAE,OAAO,CAAC,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC;QAC/D,YAAY,EAAE,OAAO,CAAC,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC;KAClE,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CACrB,cAAwB,EACxB,eAAuB,EACV,EAAE;IACf,MAAM,MAAM,GAAoB;QAC9B,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,eAAe,GAAG,CAAC;QAC7B,WAAW,EAAE,CAAC;QACd,QAAQ,EAAE,SAAyB;QACnC,SAAS,EAAE,MA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AE,MAAM,EAAE,CAAC,CAAC;QAExD,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,QAAQ,CAClB,UAAU,EACV,KAAK,EACL,KAAK,EACL,KAAK,EACL,SAAS,EACT,UAAU,CACX,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { UserOptions } from \"jspdf-autotable\";\nimport { CellStyleData, CellValueProps } from \"./pdf-converter.types.js\";\nimport type {\n Styles,\n OverflowType,\n FontStyle,\n CellHookData,\n HookData,\n} from \"jspdf-autotable\";\n\ntype TableStyles = {\n styles: Partial<Styles>;\n columnStyles: Record<string, Partial<Styles>>;\n headStyles: Partial<Styles>;\n};\n\nexport const getAutoTableOptions = (\n visibleHeaders: string[],\n data: CellValueProps[][],\n optimalFontSize: number,\n cellStyles: CellStyleData[][],\n logoBase64?: string,\n): UserOptions => {\n const { styles, columnStyles, headStyles } = getTableStyles(\n visibleHeaders,\n optimalFontSize,\n );\n return {\n head: [visibleHeaders],\n body: data.map(row => row.map(cell => cell.text)),\n startY: 25,\n margin: { left: 5, right: 5, top: 25, bottom: 10 },\n styles,\n columnStyles,\n headStyles,\n didDrawPage: dataArg => didDrawPageHandler(dataArg, logoBase64),\n didParseCell: dataArg => didParseCellHandler(dataArg, cellStyles),\n };\n};\n\nconst getTableStyles = (\n visibleHeaders: string[],\n optimalFontSize: number,\n): TableStyles => {\n const styles: Partial<Styles> = {\n font: \"helvetica\",\n fontSize: optimalFontSize + 1,\n cellPadding: 1,\n overflow: \"visible\" as OverflowType,\n cellWidth: \"auto\",\n minCellWidth: 5,\n };\n\n const columnStyles: { [key: string]: Partial<Styles> } = {\n ...Object.fromEntries(\n visibleHeaders.map((_, index) => [\n index,\n {\n cellWidth: \"wrap\",\n halign: \"left\",\n overflow: \"visible\" as OverflowType,\n cellPadding: { top: 1, right: 1, bottom: 1, left: 1 },\n },\n ]),\n ),\n };\n\n const headStyles: Partial<Styles> = {\n fillColor: [255, 0, 0],\n textColor: [255, 255, 255],\n fontStyle: \"bold\" as FontStyle,\n halign: \"center\",\n };\n\n return { styles, columnStyles, headStyles };\n};\n\nconst didParseCellHandler = (\n dataArg: CellHookData,\n cellStyles: CellStyleData[][],\n) => {\n if (dataArg.section === \"body\") {\n const rowIndex = dataArg.row.index;\n const colIndex = dataArg.column.index;\n const cellStyle = cellStyles[rowIndex]?.[colIndex];\n\n if (cellStyle) {\n // Apply styles from the Excel cell\n if (cellStyle.fontStyle) {\n dataArg.cell.styles.fontStyle = cellStyle.fontStyle;\n }\n if (cellStyle.textColor) {\n dataArg.cell.styles.textColor = cellStyle.textColor;\n }\n if (cellStyle.fillColor) {\n dataArg.cell.styles.fillColor = cellStyle.fillColor;\n }\n if (cellStyle.halign === \"right\") {\n dataArg.cell.styles.halign = \"right\";\n }\n }\n }\n};\n\nconst didDrawPageHandler = (dataArg: HookData, logoBase64?: string) => {\n // Add the logo on each page\n if (logoBase64) {\n const pageWidth = dataArg.doc.internal.pageSize.getWidth();\n const logoWidth = 40; // Logo width in mm\n const logoHeight = 15; // Logo height in mm\n const logoX = pageWidth - logoWidth - 10; // 10mm from the right margin\n const logoY = 5; // 5mm from the top margin\n\n // Add the text \"Intestazione\" aligned to the left margin\n const text = \"Intestazione\";\n const textFontSize = 14;\n const textX = 5;\n const textY = 10;\n dataArg.doc.setFontSize(textFontSize);\n dataArg.doc.setFont(\"helvetica\", \"normal\");\n dataArg.doc.text(text, textX, textY, { align: \"left\" });\n\n try {\n dataArg.doc.addImage(\n logoBase64,\n \"PNG\",\n logoX,\n logoY,\n logoWidth,\n logoHeight,\n );\n } catch (error) {\n console.warn(\"Error adding logo:\", error);\n }\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createCoverPdf: (title: string, subtitle: string, subtitle2?: string) => ArrayBuffer;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as jsPDFModule from "jspdf";
|
|
2
|
+
export const createCoverPdf = (title, subtitle, subtitle2) => {
|
|
3
|
+
const doc = new jsPDFModule.jsPDF("landscape");
|
|
4
|
+
const pageWidth = doc.internal.pageSize.getWidth();
|
|
5
|
+
const titleFontSize = 24;
|
|
6
|
+
const subtitleFontSize = 16;
|
|
7
|
+
const subtitle2FontSize = 14;
|
|
8
|
+
let currentY = 45;
|
|
9
|
+
doc.setFont("helvetica", "bold");
|
|
10
|
+
doc.setFontSize(titleFontSize);
|
|
11
|
+
doc.text(title, pageWidth / 2, currentY, { align: "center" });
|
|
12
|
+
currentY += 1;
|
|
13
|
+
if (subtitle) {
|
|
14
|
+
doc.setFont("helvetica", "normal");
|
|
15
|
+
doc.setFontSize(subtitleFontSize);
|
|
16
|
+
currentY += subtitleFontSize - 8;
|
|
17
|
+
doc.text(subtitle, pageWidth / 2, currentY, { align: "center" });
|
|
18
|
+
}
|
|
19
|
+
if (subtitle2) {
|
|
20
|
+
doc.setFontSize(subtitle2FontSize);
|
|
21
|
+
currentY += subtitle2FontSize;
|
|
22
|
+
doc.text(subtitle2, pageWidth / 2, currentY, { align: "center" });
|
|
23
|
+
}
|
|
24
|
+
return doc.output("arraybuffer");
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=cover-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cover-renderer.js","sourceRoot":"","sources":["../../../src/converters/pdf/cover-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,OAAO,CAAC;AAErC,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAa,EACb,QAAgB,EAChB,SAAkB,EAClB,EAAE;IACF,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;IACnD,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,MAAM,gBAAgB,GAAG,EAAE,CAAC;IAC5B,MAAM,iBAAiB,GAAG,EAAE,CAAC;IAC7B,IAAI,QAAQ,GAAG,EAAE,CAAC;IAElB,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACjC,GAAG,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAC/B,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC9D,QAAQ,IAAI,CAAC,CAAC;IAEd,IAAI,QAAQ,EAAE,CAAC;QACb,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACnC,GAAG,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;QAClC,QAAQ,IAAI,gBAAgB,GAAG,CAAC,CAAC;QACjC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QACnC,QAAQ,IAAI,iBAAiB,CAAC;QAC9B,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC,CAAC","sourcesContent":["import * as jsPDFModule from \"jspdf\";\n\nexport const createCoverPdf = (\n title: string,\n subtitle: string,\n subtitle2?: string,\n) => {\n const doc = new jsPDFModule.jsPDF(\"landscape\");\n const pageWidth = doc.internal.pageSize.getWidth();\n const titleFontSize = 24;\n const subtitleFontSize = 16;\n const subtitle2FontSize = 14;\n let currentY = 45;\n\n doc.setFont(\"helvetica\", \"bold\");\n doc.setFontSize(titleFontSize);\n doc.text(title, pageWidth / 2, currentY, { align: \"center\" });\n currentY += 1;\n\n if (subtitle) {\n doc.setFont(\"helvetica\", \"normal\");\n doc.setFontSize(subtitleFontSize);\n currentY += subtitleFontSize - 8;\n doc.text(subtitle, pageWidth / 2, currentY, { align: \"center\" });\n }\n\n if (subtitle2) {\n doc.setFontSize(subtitle2FontSize);\n currentY += subtitle2FontSize;\n doc.text(subtitle2, pageWidth / 2, currentY, { align: \"center\" });\n }\n\n return doc.output(\"arraybuffer\");\n};\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { WebupManagerData } from "../../types/index.js";
|
|
2
|
+
import { CellValueProps } from "./pdf-converter.types.js";
|
|
3
|
+
import ExcelJS from "exceljs";
|
|
4
|
+
/**
|
|
5
|
+
* Handles the calculation of Excel-like SUBTOTAL formulas for a given cell and range.
|
|
6
|
+
*
|
|
7
|
+
* Supports various SUBTOTAL types such as SUM, AVERAGE, COUNTA, MAX, and MIN.
|
|
8
|
+
* The function extracts the relevant range from the worksheet, computes the result
|
|
9
|
+
* based on the subtotal type, and formats the output as needed (including date and number formatting).
|
|
10
|
+
*
|
|
11
|
+
* @param cell - The ExcelJS cell object where the formula is applied.
|
|
12
|
+
* @param worksheet - The ExcelJS worksheet containing the data range.
|
|
13
|
+
* @param webupManagerData - Additional data/context used for formatting numbers and dates.
|
|
14
|
+
* @param subtotalMatch - The RegExp match array containing the parsed SUBTOTAL formula components:
|
|
15
|
+
* - [1]: The subtotal type (e.g., 1 for AVERAGE, 3 for COUNTA, 4 for MAX, 5 for MIN, 9 for SUM).
|
|
16
|
+
* - [2]: The start cell reference of the range.
|
|
17
|
+
* - [3]: The end cell reference of the range.
|
|
18
|
+
* @returns An object containing the computed value and its type ("number" or "string").
|
|
19
|
+
*/
|
|
20
|
+
export declare const handleSubtotalFormula: (cell: ExcelJS.Cell, worksheet: ExcelJS.Worksheet, webupManagerData: WebupManagerData, subtotalMatch: RegExpMatchArray) => CellValueProps;
|
|
21
|
+
/**
|
|
22
|
+
* Evaluates a standard Excel formula from a given cell by replacing cell references
|
|
23
|
+
* with their actual values from the worksheet and then computing the result.
|
|
24
|
+
*
|
|
25
|
+
* - Replaces cell references (e.g., "A1") in the formula with their corresponding values.
|
|
26
|
+
* - Handles different cell value types: number, string, formula result, and date.
|
|
27
|
+
* - Evaluates the resulting formula string using a safe function context.
|
|
28
|
+
* - Applies number formatting if the result is numeric and a format is specified.
|
|
29
|
+
* - Returns the computed value and its type ("number" or "string").
|
|
30
|
+
*
|
|
31
|
+
* @param cell - The ExcelJS cell containing the formula to evaluate.
|
|
32
|
+
* @param worksheet - The ExcelJS worksheet object for resolving cell references.
|
|
33
|
+
* @param webupManagerData - Additional data used for number formatting.
|
|
34
|
+
* @returns An object containing the evaluated value and its type.
|
|
35
|
+
*/
|
|
36
|
+
export declare const evaluateStandardFormula: (cell: ExcelJS.Cell, worksheet: ExcelJS.Worksheet, webupManagerData: WebupManagerData) => CellValueProps;
|
|
37
|
+
/**
|
|
38
|
+
* Extracts and formats the value of a given ExcelJS cell based on its type.
|
|
39
|
+
*/
|
|
40
|
+
export declare const getCellValueData: (cell: ExcelJS.Cell, worksheet: ExcelJS.Worksheet, webupManagerData: WebupManagerData) => CellValueProps;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { getCellsFromRange } from "../excel/commons.js";
|
|
2
|
+
import { areAllValuesDates } from "../../utils/dates-utility.js";
|
|
3
|
+
import { formatDate, formatNumber } from "../../utils/formatter-utility.js";
|
|
4
|
+
import ExcelJS from "exceljs";
|
|
5
|
+
import { calculateExpression } from "../../utils/math-utility.js";
|
|
6
|
+
/**
|
|
7
|
+
* Handles the calculation of Excel-like SUBTOTAL formulas for a given cell and range.
|
|
8
|
+
*
|
|
9
|
+
* Supports various SUBTOTAL types such as SUM, AVERAGE, COUNTA, MAX, and MIN.
|
|
10
|
+
* The function extracts the relevant range from the worksheet, computes the result
|
|
11
|
+
* based on the subtotal type, and formats the output as needed (including date and number formatting).
|
|
12
|
+
*
|
|
13
|
+
* @param cell - The ExcelJS cell object where the formula is applied.
|
|
14
|
+
* @param worksheet - The ExcelJS worksheet containing the data range.
|
|
15
|
+
* @param webupManagerData - Additional data/context used for formatting numbers and dates.
|
|
16
|
+
* @param subtotalMatch - The RegExp match array containing the parsed SUBTOTAL formula components:
|
|
17
|
+
* - [1]: The subtotal type (e.g., 1 for AVERAGE, 3 for COUNTA, 4 for MAX, 5 for MIN, 9 for SUM).
|
|
18
|
+
* - [2]: The start cell reference of the range.
|
|
19
|
+
* - [3]: The end cell reference of the range.
|
|
20
|
+
* @returns An object containing the computed value and its type ("number" or "string").
|
|
21
|
+
*/
|
|
22
|
+
export const handleSubtotalFormula = (cell, worksheet, webupManagerData, subtotalMatch) => {
|
|
23
|
+
const subtotalType = parseInt(subtotalMatch[1], 10);
|
|
24
|
+
const startRef = subtotalMatch[2];
|
|
25
|
+
const endRef = subtotalMatch[3];
|
|
26
|
+
const cells = getCellsFromRange(worksheet, startRef, endRef).filter(cell => cell.type !== ExcelJS.ValueType.Formula);
|
|
27
|
+
let result;
|
|
28
|
+
const areAllDates = areAllValuesDates(cells);
|
|
29
|
+
switch (subtotalType) {
|
|
30
|
+
case 3: // COUNTA
|
|
31
|
+
result = cells.length;
|
|
32
|
+
break;
|
|
33
|
+
case 9: // SUM
|
|
34
|
+
result = cells.reduce((sum, cell) => {
|
|
35
|
+
const n = typeof cell.value === "number"
|
|
36
|
+
? cell.value
|
|
37
|
+
: typeof cell.value === "string"
|
|
38
|
+
? parseFloat(cell.value)
|
|
39
|
+
: NaN;
|
|
40
|
+
return !isNaN(n)
|
|
41
|
+
? (typeof sum === "number"
|
|
42
|
+
? sum
|
|
43
|
+
: typeof sum === "string"
|
|
44
|
+
? parseFloat(sum)
|
|
45
|
+
: 0) + n
|
|
46
|
+
: sum;
|
|
47
|
+
}, 0);
|
|
48
|
+
break;
|
|
49
|
+
case 4: // MAX
|
|
50
|
+
result = cells.length
|
|
51
|
+
? Math.max(...cells.map(cell => {
|
|
52
|
+
if (cell.type === ExcelJS.ValueType.Date) {
|
|
53
|
+
return cell.value instanceof Date
|
|
54
|
+
? cell.value.getTime()
|
|
55
|
+
: -Infinity;
|
|
56
|
+
}
|
|
57
|
+
return typeof cell.value === "number"
|
|
58
|
+
? cell.value
|
|
59
|
+
: (typeof cell.value === "string"
|
|
60
|
+
? parseFloat(cell.value)
|
|
61
|
+
: -Infinity) || -Infinity;
|
|
62
|
+
}))
|
|
63
|
+
: "";
|
|
64
|
+
break;
|
|
65
|
+
case 5: // MIN
|
|
66
|
+
result = cells.length
|
|
67
|
+
? Math.min(...cells.map(cell => {
|
|
68
|
+
if (cell.type === ExcelJS.ValueType.Date) {
|
|
69
|
+
return cell.value instanceof Date
|
|
70
|
+
? cell.value.getTime()
|
|
71
|
+
: Infinity;
|
|
72
|
+
}
|
|
73
|
+
return typeof cell.value === "number"
|
|
74
|
+
? cell.value
|
|
75
|
+
: (typeof cell.value === "string"
|
|
76
|
+
? parseFloat(cell.value)
|
|
77
|
+
: Infinity) || Infinity;
|
|
78
|
+
}))
|
|
79
|
+
: "";
|
|
80
|
+
break;
|
|
81
|
+
case 1: {
|
|
82
|
+
// AVERAGE
|
|
83
|
+
const nums = cells
|
|
84
|
+
.map(cell => typeof cell.value === "number"
|
|
85
|
+
? cell.value
|
|
86
|
+
: typeof cell.value === "string"
|
|
87
|
+
? parseFloat(cell.value)
|
|
88
|
+
: NaN)
|
|
89
|
+
.filter(v => !isNaN(v));
|
|
90
|
+
result = nums.length ? nums.reduce((a, b) => a + b, 0) / nums.length : "";
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
default: {
|
|
94
|
+
if (cell.result != null && typeof cell.result !== "object") {
|
|
95
|
+
result = cell.result;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
result =
|
|
99
|
+
cell.text ||
|
|
100
|
+
(typeof cell.value === "string" || typeof cell.value === "number"
|
|
101
|
+
? cell.value
|
|
102
|
+
: "") ||
|
|
103
|
+
"";
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (areAllDates) {
|
|
109
|
+
return {
|
|
110
|
+
value: result,
|
|
111
|
+
text: formatDate(new Date(result), webupManagerData),
|
|
112
|
+
type: "date",
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
else if (typeof result === "number" && cell.numFmt) {
|
|
116
|
+
return {
|
|
117
|
+
value: result,
|
|
118
|
+
text: formatNumber(result, cell.numFmt, webupManagerData),
|
|
119
|
+
type: "number",
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
value: result,
|
|
124
|
+
text: result.toString(),
|
|
125
|
+
type: typeof result === "number" ? "number" : "string",
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Evaluates a standard Excel formula from a given cell by replacing cell references
|
|
130
|
+
* with their actual values from the worksheet and then computing the result.
|
|
131
|
+
*
|
|
132
|
+
* - Replaces cell references (e.g., "A1") in the formula with their corresponding values.
|
|
133
|
+
* - Handles different cell value types: number, string, formula result, and date.
|
|
134
|
+
* - Evaluates the resulting formula string using a safe function context.
|
|
135
|
+
* - Applies number formatting if the result is numeric and a format is specified.
|
|
136
|
+
* - Returns the computed value and its type ("number" or "string").
|
|
137
|
+
*
|
|
138
|
+
* @param cell - The ExcelJS cell containing the formula to evaluate.
|
|
139
|
+
* @param worksheet - The ExcelJS worksheet object for resolving cell references.
|
|
140
|
+
* @param webupManagerData - Additional data used for number formatting.
|
|
141
|
+
* @returns An object containing the evaluated value and its type.
|
|
142
|
+
*/
|
|
143
|
+
export const evaluateStandardFormula = (cell, worksheet, webupManagerData) => {
|
|
144
|
+
const formula = cell.formula;
|
|
145
|
+
const formulaWithSolvedVariables = formula.replace(/([A-Z]+\d+)/g, ref => {
|
|
146
|
+
try {
|
|
147
|
+
const refCell = worksheet.getCell(ref);
|
|
148
|
+
if (refCell) {
|
|
149
|
+
if (refCell.type === ExcelJS.ValueType.Number) {
|
|
150
|
+
return refCell.value?.toString() ?? "0";
|
|
151
|
+
}
|
|
152
|
+
else if (refCell.type === ExcelJS.ValueType.String) {
|
|
153
|
+
// If the cell contains text, return as is (no quotes) for JS compatibility
|
|
154
|
+
return refCell.value?.toString() ?? "";
|
|
155
|
+
}
|
|
156
|
+
else if (refCell.type === ExcelJS.ValueType.Formula) {
|
|
157
|
+
return getCellValueData(refCell, worksheet, webupManagerData).value.toString();
|
|
158
|
+
}
|
|
159
|
+
else if (refCell.type === ExcelJS.ValueType.Date &&
|
|
160
|
+
refCell.value instanceof Date) {
|
|
161
|
+
return refCell.value.getTime().toString();
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return refCell.value?.toString() ?? "0";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return "0";
|
|
170
|
+
}
|
|
171
|
+
return "0";
|
|
172
|
+
});
|
|
173
|
+
const result = calculateExpression(formulaWithSolvedVariables);
|
|
174
|
+
// If the result is a number and a format is specified, apply it
|
|
175
|
+
if (typeof result === "number" && cell.numFmt) {
|
|
176
|
+
return {
|
|
177
|
+
value: result,
|
|
178
|
+
text: formatNumber(result, cell.numFmt, webupManagerData),
|
|
179
|
+
type: "number",
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
value: result,
|
|
184
|
+
text: result != null ? result.toString() : cell.formula,
|
|
185
|
+
type: typeof result === "number" ? "number" : "string",
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Extracts and formats the value of a given ExcelJS cell based on its type.
|
|
190
|
+
*/
|
|
191
|
+
export const getCellValueData = (cell, worksheet, webupManagerData) => {
|
|
192
|
+
if (cell.type === ExcelJS.ValueType.Formula &&
|
|
193
|
+
typeof cell.formula === "string") {
|
|
194
|
+
const subtotalMatch = cell.formula.match(/^SUBTOTAL\((\d+)\s*,\s*([A-Z]+\d+):([A-Z]+\d+)\)/i);
|
|
195
|
+
if (subtotalMatch) {
|
|
196
|
+
return handleSubtotalFormula(cell, worksheet, webupManagerData, subtotalMatch);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
return evaluateStandardFormula(cell, worksheet, webupManagerData);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else if (cell.type === ExcelJS.ValueType.Date &&
|
|
203
|
+
cell.value instanceof Date) {
|
|
204
|
+
return {
|
|
205
|
+
value: cell.value,
|
|
206
|
+
text: formatDate(cell.value, webupManagerData),
|
|
207
|
+
type: "date",
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
else if (cell.type === ExcelJS.ValueType.Number) {
|
|
211
|
+
return {
|
|
212
|
+
value: cell.value,
|
|
213
|
+
text: formatNumber(cell.value, cell.numFmt ?? 0, webupManagerData),
|
|
214
|
+
type: "number",
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
// Fallback to text or value if available, otherwise empty string
|
|
219
|
+
const value = cell?.text || cell?.value?.toString() || "";
|
|
220
|
+
return {
|
|
221
|
+
value: value,
|
|
222
|
+
text: value,
|
|
223
|
+
type: "string",
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
//# sourceMappingURL=formulas-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formulas-helper.js","sourceRoot":"","sources":["../../../src/converters/pdf/formulas-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kCAAk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AAC,SAAS,CAAC,MAAM,EAAE,CAAC;QAClD,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAe;YAC3B,IAAI,EAAE,YAAY,CAChB,IAAI,CAAC,KAAe,EACpB,IAAI,CAAC,MAAM,IAAI,CAAC,EAChB,gBAAgB,CACjB;YACD,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,MAAM,KAAK,GAAG,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC1D,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,QAAQ;SACf,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { getCellsFromRange } from \"../excel/commons.js\";\nimport { WebupManagerData } from \"../../types/index.js\";\nimport { areAllValuesDates } from \"../../utils/dates-utility.js\";\nimport { formatDate, formatNumber } from \"../../utils/formatter-utility.js\";\nimport { CellValueProps } from \"./pdf-converter.types.js\";\nimport ExcelJS from \"exceljs\";\nimport { calculateExpression } from \"../../utils/math-utility.js\";\n\n/**\n * Handles the calculation of Excel-like SUBTOTAL formulas for a given cell and range.\n *\n * Supports various SUBTOTAL types such as SUM, AVERAGE, COUNTA, MAX, and MIN.\n * The function extracts the relevant range from the worksheet, computes the result\n * based on the subtotal type, and formats the output as needed (including date and number formatting).\n *\n * @param cell - The ExcelJS cell object where the formula is applied.\n * @param worksheet - The ExcelJS worksheet containing the data range.\n * @param webupManagerData - Additional data/context used for formatting numbers and dates.\n * @param subtotalMatch - The RegExp match array containing the parsed SUBTOTAL formula components:\n * - [1]: The subtotal type (e.g., 1 for AVERAGE, 3 for COUNTA, 4 for MAX, 5 for MIN, 9 for SUM).\n * - [2]: The start cell reference of the range.\n * - [3]: The end cell reference of the range.\n * @returns An object containing the computed value and its type (\"number\" or \"string\").\n */\nexport const handleSubtotalFormula = (\n cell: ExcelJS.Cell,\n worksheet: ExcelJS.Worksheet,\n webupManagerData: WebupManagerData,\n subtotalMatch: RegExpMatchArray,\n): CellValueProps => {\n const subtotalType = parseInt(subtotalMatch[1], 10);\n const startRef = subtotalMatch[2];\n const endRef = subtotalMatch[3];\n const cells = getCellsFromRange(worksheet, startRef, endRef).filter(\n cell => cell.type !== ExcelJS.ValueType.Formula,\n );\n let result: number | string | \"\";\n const areAllDates = areAllValuesDates(cells);\n switch (subtotalType) {\n case 3: // COUNTA\n result = cells.length;\n break;\n case 9: // SUM\n result = cells.reduce((sum, cell) => {\n const n =\n typeof cell.value === \"number\"\n ? cell.value\n : typeof cell.value === \"string\"\n ? parseFloat(cell.value)\n : NaN;\n return !isNaN(n)\n ? (typeof sum === \"number\"\n ? sum\n : typeof sum === \"string\"\n ? parseFloat(sum)\n : 0) + n\n : sum;\n }, 0);\n break;\n case 4: // MAX\n result = cells.length\n ? Math.max(\n ...cells.map(cell => {\n if (cell.type === ExcelJS.ValueType.Date) {\n return cell.value instanceof Date\n ? cell.value.getTime()\n : -Infinity;\n }\n return typeof cell.value === \"number\"\n ? cell.value\n : (typeof cell.value === \"string\"\n ? parseFloat(cell.value)\n : -Infinity) || -Infinity;\n }),\n )\n : \"\";\n break;\n case 5: // MIN\n result = cells.length\n ? Math.min(\n ...cells.map(cell => {\n if (cell.type === ExcelJS.ValueType.Date) {\n return cell.value instanceof Date\n ? cell.value.getTime()\n : Infinity;\n }\n return typeof cell.value === \"number\"\n ? cell.value\n : (typeof cell.value === \"string\"\n ? parseFloat(cell.value)\n : Infinity) || Infinity;\n }),\n )\n : \"\";\n break;\n case 1: {\n // AVERAGE\n const nums = cells\n .map(cell =>\n typeof cell.value === \"number\"\n ? cell.value\n : typeof cell.value === \"string\"\n ? parseFloat(cell.value)\n : NaN,\n )\n .filter(v => !isNaN(v));\n result = nums.length ? nums.reduce((a, b) => a + b, 0) / nums.length : \"\";\n break;\n }\n default: {\n if (cell.result != null && typeof cell.result !== \"object\") {\n result = cell.result;\n } else {\n result =\n cell.text ||\n (typeof cell.value === \"string\" || typeof cell.value === \"number\"\n ? cell.value\n : \"\") ||\n \"\";\n }\n break;\n }\n }\n\n if (areAllDates) {\n return {\n value: result,\n text: formatDate(new Date(result), webupManagerData),\n type: \"date\",\n };\n } else if (typeof result === \"number\" && cell.numFmt) {\n return {\n value: result,\n text: formatNumber(result, cell.numFmt, webupManagerData),\n type: \"number\",\n };\n }\n return {\n value: result,\n text: result.toString(),\n type: typeof result === \"number\" ? \"number\" : \"string\",\n };\n};\n\n/**\n * Evaluates a standard Excel formula from a given cell by replacing cell references\n * with their actual values from the worksheet and then computing the result.\n *\n * - Replaces cell references (e.g., \"A1\") in the formula with their corresponding values.\n * - Handles different cell value types: number, string, formula result, and date.\n * - Evaluates the resulting formula string using a safe function context.\n * - Applies number formatting if the result is numeric and a format is specified.\n * - Returns the computed value and its type (\"number\" or \"string\").\n *\n * @param cell - The ExcelJS cell containing the formula to evaluate.\n * @param worksheet - The ExcelJS worksheet object for resolving cell references.\n * @param webupManagerData - Additional data used for number formatting.\n * @returns An object containing the evaluated value and its type.\n */\nexport const evaluateStandardFormula = (\n cell: ExcelJS.Cell,\n worksheet: ExcelJS.Worksheet,\n webupManagerData: WebupManagerData,\n): CellValueProps => {\n const formula = cell.formula;\n const formulaWithSolvedVariables = formula.replace(/([A-Z]+\\d+)/g, ref => {\n try {\n const refCell = worksheet.getCell(ref);\n if (refCell) {\n if (refCell.type === ExcelJS.ValueType.Number) {\n return refCell.value?.toString() ?? \"0\";\n } else if (refCell.type === ExcelJS.ValueType.String) {\n // If the cell contains text, return as is (no quotes) for JS compatibility\n return refCell.value?.toString() ?? \"\";\n } else if (refCell.type === ExcelJS.ValueType.Formula) {\n return getCellValueData(\n refCell,\n worksheet,\n webupManagerData,\n ).value.toString();\n } else if (\n refCell.type === ExcelJS.ValueType.Date &&\n refCell.value instanceof Date\n ) {\n return refCell.value.getTime().toString();\n } else {\n return refCell.value?.toString() ?? \"0\";\n }\n }\n } catch {\n return \"0\";\n }\n return \"0\";\n });\n const result = calculateExpression(formulaWithSolvedVariables);\n // If the result is a number and a format is specified, apply it\n if (typeof result === \"number\" && cell.numFmt) {\n return {\n value: result,\n text: formatNumber(result, cell.numFmt, webupManagerData),\n type: \"number\",\n };\n }\n return {\n value: result,\n text: result != null ? result.toString() : cell.formula,\n type: typeof result === \"number\" ? \"number\" : \"string\",\n };\n};\n\n/**\n * Extracts and formats the value of a given ExcelJS cell based on its type.\n */\nexport const getCellValueData = (\n cell: ExcelJS.Cell,\n worksheet: ExcelJS.Worksheet,\n webupManagerData: WebupManagerData,\n): CellValueProps => {\n if (\n cell.type === ExcelJS.ValueType.Formula &&\n typeof cell.formula === \"string\"\n ) {\n const subtotalMatch = cell.formula.match(\n /^SUBTOTAL\\((\\d+)\\s*,\\s*([A-Z]+\\d+):([A-Z]+\\d+)\\)/i,\n );\n if (subtotalMatch) {\n return handleSubtotalFormula(\n cell,\n worksheet,\n webupManagerData,\n subtotalMatch,\n );\n } else {\n return evaluateStandardFormula(cell, worksheet, webupManagerData);\n }\n } else if (\n cell.type === ExcelJS.ValueType.Date &&\n cell.value instanceof Date\n ) {\n return {\n value: cell.value,\n text: formatDate(cell.value, webupManagerData),\n type: \"date\",\n };\n } else if (cell.type === ExcelJS.ValueType.Number) {\n return {\n value: cell.value as number,\n text: formatNumber(\n cell.value as number,\n cell.numFmt ?? 0,\n webupManagerData,\n ),\n type: \"number\",\n };\n } else {\n // Fallback to text or value if available, otherwise empty string\n const value = cell?.text || cell?.value?.toString() || \"\";\n return {\n value: value,\n text: value,\n type: \"string\",\n };\n }\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as jsPDFModule from "jspdf";
|
|
2
|
+
import ExcelJS from "exceljs";
|
|
3
|
+
import { WebupManagerData } from "../../index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Converts an ExcelJS worksheet into a PDF document using jsPDF and autoTable.
|
|
6
|
+
*
|
|
7
|
+
* This function extracts visible headers and data from the provided worksheet,
|
|
8
|
+
* applies cell styles, simulates Excel cell overflow, and calculates the optimal
|
|
9
|
+
* font size for the table. It then generates a PDF document with the formatted
|
|
10
|
+
* table and returns the resulting jsPDF instance.
|
|
11
|
+
*
|
|
12
|
+
* @param worksheet - The ExcelJS worksheet to convert to PDF.
|
|
13
|
+
* @param webupManagerData - Additional data required for extracting worksheet content.
|
|
14
|
+
* @returns A Promise that resolves to a jsPDF document containing the worksheet data as a table.
|
|
15
|
+
*/
|
|
16
|
+
export declare const dataTableToPdfDoc: (worksheet: ExcelJS.Worksheet, webupManagerData: WebupManagerData) => Promise<jsPDFModule.jsPDF>;
|