intelica-library-ui 0.1.54 → 0.1.55
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.
|
@@ -2380,7 +2380,7 @@ class HtmlToExcelService {
|
|
|
2380
2380
|
horizontal: "center",
|
|
2381
2381
|
wrapText: true,
|
|
2382
2382
|
};
|
|
2383
|
-
async ExportToExcel(excelName, reportTitle, filterTitle, rowsSerializate, columns, filters) {
|
|
2383
|
+
async ExportToExcel(excelName, reportTitle, filterTitle, rowsSerializate, columns, filters, subtitles = [], showTotalRow = false) {
|
|
2384
2384
|
const workbook = new Workbook();
|
|
2385
2385
|
const worksheet = workbook.addWorksheet(reportTitle);
|
|
2386
2386
|
worksheet.views = [{ showGridLines: false }];
|
|
@@ -2388,7 +2388,7 @@ class HtmlToExcelService {
|
|
|
2388
2388
|
base64: this.Logo,
|
|
2389
2389
|
extension: "png",
|
|
2390
2390
|
});
|
|
2391
|
-
this.SetReportPage(rowsSerializate, worksheet, columns, imageId);
|
|
2391
|
+
this.SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles, showTotalRow);
|
|
2392
2392
|
this.SetTitle(worksheet, reportTitle);
|
|
2393
2393
|
if (filters.length > 0) {
|
|
2394
2394
|
const worksheetFilter = workbook.addWorksheet(filterTitle);
|
|
@@ -2410,27 +2410,68 @@ class HtmlToExcelService {
|
|
|
2410
2410
|
};
|
|
2411
2411
|
titleCell.alignment = { vertical: "middle", horizontal: "center" };
|
|
2412
2412
|
}
|
|
2413
|
-
SetReportPage(rowsSerializate, worksheet, columns, imageId) {
|
|
2413
|
+
SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles = [], showTotalRow = false) {
|
|
2414
2414
|
let columnsCell = [];
|
|
2415
2415
|
let cells = [];
|
|
2416
2416
|
let rows = JSON.parse(rowsSerializate);
|
|
2417
|
+
//Inserción de filas para imagen
|
|
2418
|
+
const imageRows = 5;
|
|
2417
2419
|
const numberRows = rows.length;
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
worksheet.addRow([""]);
|
|
2420
|
+
for (let i = 0; i < subtitles.length + imageRows; i++) {
|
|
2421
|
+
worksheet.addRow([""]);
|
|
2422
|
+
}
|
|
2423
|
+
//Inserción de nombre de columnas
|
|
2423
2424
|
let columnsNames = [];
|
|
2425
|
+
let startRow = imageRows + 1 + subtitles.length;
|
|
2424
2426
|
for (let i = 0; i < columns.length; i++) {
|
|
2425
|
-
let cell = `${String.fromCharCode(65 + i)}
|
|
2427
|
+
let cell = `${String.fromCharCode(65 + i)}${startRow}`;
|
|
2426
2428
|
columnsNames.push(columns[i].displayColumnName);
|
|
2427
2429
|
columnsCell.push(cell);
|
|
2428
2430
|
}
|
|
2429
2431
|
worksheet.addRow(columnsNames);
|
|
2432
|
+
//Inserción y formato de sumatorias
|
|
2433
|
+
if (showTotalRow) {
|
|
2434
|
+
const sums = columns.map(col => {
|
|
2435
|
+
if (!col.totalRowValue)
|
|
2436
|
+
return null;
|
|
2437
|
+
return rows.reduce((acc, row) => {
|
|
2438
|
+
const value = parseFloat(row[col.columnName]) || 0;
|
|
2439
|
+
return acc + value;
|
|
2440
|
+
}, 0);
|
|
2441
|
+
});
|
|
2442
|
+
const sumRow = columns.map((col, index) => {
|
|
2443
|
+
if (col.columnName === "")
|
|
2444
|
+
return "Total";
|
|
2445
|
+
if (!col.totalRowValue)
|
|
2446
|
+
return "";
|
|
2447
|
+
return (sums[index]?.toLocaleString(undefined, {
|
|
2448
|
+
minimumFractionDigits: 2,
|
|
2449
|
+
maximumFractionDigits: 2,
|
|
2450
|
+
}) || "0.00");
|
|
2451
|
+
});
|
|
2452
|
+
startRow = startRow + 1;
|
|
2453
|
+
worksheet.insertRow(startRow, sumRow);
|
|
2454
|
+
columns.forEach((col, index) => {
|
|
2455
|
+
const cellAddress = `${String.fromCharCode(65 + index)}${startRow}`;
|
|
2456
|
+
const cell = worksheet.getCell(cellAddress);
|
|
2457
|
+
cell.font = {
|
|
2458
|
+
name: "Arial",
|
|
2459
|
+
bold: true,
|
|
2460
|
+
size: 10,
|
|
2461
|
+
color: { argb: "FF7F00" },
|
|
2462
|
+
};
|
|
2463
|
+
cell.alignment = {
|
|
2464
|
+
vertical: "middle",
|
|
2465
|
+
horizontal: col.isNumber ? "right" : "left",
|
|
2466
|
+
};
|
|
2467
|
+
cell.border = { bottom: { style: "thin", color: { argb: "FF7F00" } } };
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
//Inserción de filas
|
|
2430
2471
|
for (let rowIndex = 0; rowIndex < numberRows; rowIndex++) {
|
|
2431
2472
|
let rowCells = [];
|
|
2432
2473
|
let rowValues = [];
|
|
2433
|
-
let index = rowIndex +
|
|
2474
|
+
let index = rowIndex + startRow + 1;
|
|
2434
2475
|
for (let columIndex = 0; columIndex < columns.length; columIndex++) {
|
|
2435
2476
|
let cell = `${String.fromCharCode(65 + columIndex)}${index}`;
|
|
2436
2477
|
rowCells.push(cell);
|
|
@@ -2443,6 +2484,7 @@ class HtmlToExcelService {
|
|
|
2443
2484
|
worksheet.addRow(rowValues);
|
|
2444
2485
|
cells.push({ index: index, cells: rowCells });
|
|
2445
2486
|
}
|
|
2487
|
+
//Formato nombre de columnas
|
|
2446
2488
|
columnsCell.map(key => {
|
|
2447
2489
|
worksheet.getCell(key).fill = {
|
|
2448
2490
|
type: "pattern",
|
|
@@ -2458,6 +2500,7 @@ class HtmlToExcelService {
|
|
|
2458
2500
|
};
|
|
2459
2501
|
worksheet.getCell(key).alignment = this.ColumnAligment;
|
|
2460
2502
|
});
|
|
2503
|
+
//Formato de filas
|
|
2461
2504
|
cells.forEach(element => {
|
|
2462
2505
|
element.cells.map(key => {
|
|
2463
2506
|
if (element.index % 2 !== 1) {
|
|
@@ -2476,12 +2519,29 @@ class HtmlToExcelService {
|
|
|
2476
2519
|
};
|
|
2477
2520
|
});
|
|
2478
2521
|
});
|
|
2522
|
+
//Logo intelica
|
|
2479
2523
|
worksheet.addImage(imageId, {
|
|
2480
2524
|
tl: { col: 0.5, row: 1.5 },
|
|
2481
2525
|
ext: { width: 218, height: 58 },
|
|
2482
2526
|
editAs: "absolute",
|
|
2483
2527
|
});
|
|
2484
2528
|
this.AdjustColumnWidth(worksheet, columns);
|
|
2529
|
+
//Subtitulos: Se inserta al final para evitar altere el autoajuste de las columnas
|
|
2530
|
+
for (let i = 0; i < subtitles.length; i++) {
|
|
2531
|
+
const range = `${String.fromCharCode(65)}${6 + i}:${String.fromCharCode(79)}${6 + i}`;
|
|
2532
|
+
worksheet.mergeCells(range);
|
|
2533
|
+
const cell = worksheet.getCell(`${String.fromCharCode(65)}${6 + i}`);
|
|
2534
|
+
const subtitle = subtitles[i];
|
|
2535
|
+
cell.value = subtitle;
|
|
2536
|
+
cell.font = {
|
|
2537
|
+
name: "Arial",
|
|
2538
|
+
bold: true,
|
|
2539
|
+
italic: true,
|
|
2540
|
+
size: 10,
|
|
2541
|
+
color: { argb: "203764" },
|
|
2542
|
+
};
|
|
2543
|
+
cell.alignment = { vertical: "middle", horizontal: "left", wrapText: true };
|
|
2544
|
+
}
|
|
2485
2545
|
}
|
|
2486
2546
|
SetFilterPage(filterTitle, worksheetFilter, filters) {
|
|
2487
2547
|
let widtFilter = 30;
|
|
@@ -2529,10 +2589,11 @@ class HtmlToExcelService {
|
|
|
2529
2589
|
worksheet.columns.forEach((column, index) => {
|
|
2530
2590
|
if (!column.values)
|
|
2531
2591
|
return;
|
|
2592
|
+
if (columns[index] == undefined)
|
|
2593
|
+
return;
|
|
2532
2594
|
let columnWidth = columns[index].width ?? Math.max(...column.values.map(v => (v ? v.toString().length : 0)).filter(v => typeof v === "number"), columns[index].displayColumnName.length) * 1.2;
|
|
2533
2595
|
column.width = Math.min(Math.max(columnWidth, 5), 100);
|
|
2534
2596
|
column.alignment = columns[index].isNumber ? { vertical: "middle", horizontal: "right", wrapText: true } : { vertical: "middle", horizontal: "left", wrapText: true };
|
|
2535
|
-
console.log(column.width, column);
|
|
2536
2597
|
});
|
|
2537
2598
|
worksheet.eachRow((row, rowIndex) => {
|
|
2538
2599
|
if (rowIndex === 1)
|
|
@@ -2550,6 +2611,46 @@ class HtmlToExcelService {
|
|
|
2550
2611
|
row.height = Math.min(Math.max(15 * maxLines, 15), 30);
|
|
2551
2612
|
});
|
|
2552
2613
|
}
|
|
2614
|
+
async ExportToExcelRawData({ excelName, reportTitle, filterTitle, rowsSerializate, columns, filters, orderColumn = false }) {
|
|
2615
|
+
const workbook = new Workbook();
|
|
2616
|
+
const worksheet = workbook.addWorksheet(reportTitle);
|
|
2617
|
+
const rows = JSON.parse(rowsSerializate);
|
|
2618
|
+
worksheet.views = [{ showGridLines: false }];
|
|
2619
|
+
const allColumns = orderColumn ? [{ displayColumnName: "N°" }, ...columns] : columns;
|
|
2620
|
+
allColumns.forEach((col, index) => {
|
|
2621
|
+
const headerCell = worksheet.getCell(`${String.fromCharCode(65 + index)}1`);
|
|
2622
|
+
headerCell.value = col.displayColumnName;
|
|
2623
|
+
headerCell.alignment = { horizontal: "center", vertical: "middle" };
|
|
2624
|
+
headerCell.font = { name: "Arial", bold: true, size: 10 };
|
|
2625
|
+
});
|
|
2626
|
+
const maxLengths = allColumns.map(col => col.displayColumnName.length);
|
|
2627
|
+
rows.forEach((rowData, rowIndex) => {
|
|
2628
|
+
const rowValues = allColumns.map((col, colIndex) => {
|
|
2629
|
+
if (orderColumn && colIndex === 0) {
|
|
2630
|
+
return (rowIndex + 1).toString();
|
|
2631
|
+
}
|
|
2632
|
+
const originalColIndex = orderColumn ? colIndex - 1 : colIndex;
|
|
2633
|
+
return rowData[columns[originalColIndex].columnName]?.toString() || "";
|
|
2634
|
+
});
|
|
2635
|
+
rowValues.forEach((value, i) => {
|
|
2636
|
+
const length = value.length;
|
|
2637
|
+
if (length > maxLengths[i]) {
|
|
2638
|
+
maxLengths[i] = length;
|
|
2639
|
+
}
|
|
2640
|
+
});
|
|
2641
|
+
worksheet.addRow(rowValues);
|
|
2642
|
+
});
|
|
2643
|
+
allColumns.forEach((_, index) => {
|
|
2644
|
+
worksheet.getColumn(index + 1).width = maxLengths[index] + 2;
|
|
2645
|
+
});
|
|
2646
|
+
if (filters?.length) {
|
|
2647
|
+
const worksheetFilter = workbook.addWorksheet(filterTitle);
|
|
2648
|
+
worksheetFilter.views = [{ showGridLines: false }];
|
|
2649
|
+
this.SetFilterPage(filterTitle, worksheetFilter, filters);
|
|
2650
|
+
}
|
|
2651
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
2652
|
+
saveAs(new Blob([buffer]), excelName);
|
|
2653
|
+
}
|
|
2553
2654
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: HtmlToExcelService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2554
2655
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: HtmlToExcelService, providedIn: "root" });
|
|
2555
2656
|
}
|