intelica-library-ui 0.1.194 → 0.1.195
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.
|
@@ -6436,7 +6436,9 @@ class HtmlToExcelService {
|
|
|
6436
6436
|
return;
|
|
6437
6437
|
Table.innerHTML = "";
|
|
6438
6438
|
Table.innerHTML += html;
|
|
6439
|
-
const ws = XLSX.utils.table_to_sheet(Table, {
|
|
6439
|
+
const ws = XLSX.utils.table_to_sheet(Table, {
|
|
6440
|
+
raw: false,
|
|
6441
|
+
});
|
|
6440
6442
|
const wb = XLSX.utils.book_new();
|
|
6441
6443
|
XLSX.utils.book_append_sheet(wb, ws, tabname);
|
|
6442
6444
|
XLSX.writeFile(wb, filename + "." + extension);
|
|
@@ -6447,23 +6449,48 @@ class HtmlToExcelService {
|
|
|
6447
6449
|
horizontal: "center",
|
|
6448
6450
|
wrapText: true,
|
|
6449
6451
|
};
|
|
6450
|
-
async ExportToExcel(
|
|
6452
|
+
async ExportToExcel(excelNameOrOptions, reportTitle, filterTitle, rowsSerializate, columns, filters, subtitles = [], showTotalRow = false, headerGroups = [], childKey, SheetName = "") {
|
|
6453
|
+
let options;
|
|
6454
|
+
if (typeof excelNameOrOptions === "string") {
|
|
6455
|
+
options = {
|
|
6456
|
+
excelName: excelNameOrOptions,
|
|
6457
|
+
reportTitle: reportTitle,
|
|
6458
|
+
filterTitle: filterTitle,
|
|
6459
|
+
rowsSerializate: rowsSerializate,
|
|
6460
|
+
columns: columns,
|
|
6461
|
+
filters: filters,
|
|
6462
|
+
subtitles,
|
|
6463
|
+
showTotalRow,
|
|
6464
|
+
headerGroups,
|
|
6465
|
+
childKey,
|
|
6466
|
+
SheetName,
|
|
6467
|
+
};
|
|
6468
|
+
}
|
|
6469
|
+
else {
|
|
6470
|
+
options = {
|
|
6471
|
+
subtitles: [],
|
|
6472
|
+
showTotalRow: false,
|
|
6473
|
+
headerGroups: [],
|
|
6474
|
+
SheetName: "",
|
|
6475
|
+
...excelNameOrOptions,
|
|
6476
|
+
};
|
|
6477
|
+
}
|
|
6451
6478
|
const workbook = new Workbook();
|
|
6452
|
-
const worksheet = workbook.addWorksheet(reportTitle);
|
|
6479
|
+
const worksheet = workbook.addWorksheet(options.SheetName || options.reportTitle);
|
|
6453
6480
|
worksheet.views = [{ showGridLines: false }];
|
|
6454
6481
|
const imageId = workbook.addImage({
|
|
6455
6482
|
base64: this.Logo,
|
|
6456
6483
|
extension: "png",
|
|
6457
6484
|
});
|
|
6458
|
-
this.SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles, showTotalRow, headerGroups, childKey);
|
|
6459
|
-
this.SetTitle(worksheet, reportTitle);
|
|
6460
|
-
if (filters.length > 0) {
|
|
6461
|
-
const worksheetFilter = workbook.addWorksheet(filterTitle);
|
|
6485
|
+
this.SetReportPage(options.rowsSerializate, worksheet, options.columns, imageId, options.subtitles, options.showTotalRow, options.headerGroups, options.childKey);
|
|
6486
|
+
this.SetTitle(worksheet, options.reportTitle);
|
|
6487
|
+
if (options.filters.length > 0) {
|
|
6488
|
+
const worksheetFilter = workbook.addWorksheet(options.filterTitle);
|
|
6462
6489
|
worksheetFilter.views = [{ showGridLines: false }];
|
|
6463
|
-
this.SetFilterPage(filterTitle, worksheetFilter, filters);
|
|
6490
|
+
this.SetFilterPage(options.filterTitle, worksheetFilter, options.filters);
|
|
6464
6491
|
}
|
|
6465
6492
|
const buffer = await workbook.xlsx.writeBuffer();
|
|
6466
|
-
saveAs(new Blob([buffer]), excelName);
|
|
6493
|
+
saveAs(new Blob([buffer]), options.excelName);
|
|
6467
6494
|
}
|
|
6468
6495
|
SetTitle(worksheet, reportTitle) {
|
|
6469
6496
|
worksheet.mergeCells("D1:I5");
|
|
@@ -6558,12 +6585,17 @@ class HtmlToExcelService {
|
|
|
6558
6585
|
else
|
|
6559
6586
|
startRow += 1;
|
|
6560
6587
|
if (showTotalRow) {
|
|
6561
|
-
const sums = columns.map(col => {
|
|
6588
|
+
const sums = columns.map((col) => {
|
|
6562
6589
|
if (col.columnName === "")
|
|
6563
6590
|
return "Total";
|
|
6564
6591
|
if (!col.totalRowValue)
|
|
6565
6592
|
return null;
|
|
6566
|
-
return col.totalRowValue
|
|
6593
|
+
return col.totalRowValue
|
|
6594
|
+
? {
|
|
6595
|
+
formula: `"${col.totalRowValue}"`,
|
|
6596
|
+
result: col.totalRowValue,
|
|
6597
|
+
}
|
|
6598
|
+
: null;
|
|
6567
6599
|
});
|
|
6568
6600
|
const insertedRow = worksheet.insertRow(startRow, sums);
|
|
6569
6601
|
insertedRow.eachCell((cell, colNumber) => {
|
|
@@ -6578,7 +6610,9 @@ class HtmlToExcelService {
|
|
|
6578
6610
|
vertical: "middle",
|
|
6579
6611
|
horizontal: column?.alignHorizontal ?? "left",
|
|
6580
6612
|
};
|
|
6581
|
-
cell.border = {
|
|
6613
|
+
cell.border = {
|
|
6614
|
+
bottom: { style: "thin", color: { argb: "FF7F00" } },
|
|
6615
|
+
};
|
|
6582
6616
|
if (typeof cell.value === "number") {
|
|
6583
6617
|
cell.numFmt = "0.00";
|
|
6584
6618
|
}
|
|
@@ -6596,18 +6630,20 @@ class HtmlToExcelService {
|
|
|
6596
6630
|
vertical: "middle",
|
|
6597
6631
|
horizontal: col.alignHorizontal ?? "left",
|
|
6598
6632
|
};
|
|
6599
|
-
cell.border = {
|
|
6633
|
+
cell.border = {
|
|
6634
|
+
bottom: { style: "thin", color: { argb: "FF7F00" } },
|
|
6635
|
+
};
|
|
6600
6636
|
});
|
|
6601
6637
|
startRow++;
|
|
6602
6638
|
}
|
|
6603
6639
|
//Inserción de filas
|
|
6604
6640
|
const numberColIdx = (() => {
|
|
6605
|
-
const byEmpty = columns.findIndex(c => (c.columnName ?? "").trim() === "");
|
|
6641
|
+
const byEmpty = columns.findIndex((c) => (c.columnName ?? "").trim() === "");
|
|
6606
6642
|
if (byEmpty !== -1)
|
|
6607
6643
|
return byEmpty;
|
|
6608
6644
|
const isNumDisplay = (s) => (s ?? "").trim().toLowerCase().replace("º", "°") === "n°";
|
|
6609
|
-
const byDisplay = columns.findIndex(c => isNumDisplay(c.displayColumnName));
|
|
6610
|
-
const byColumnName = columns.findIndex(c => isNumDisplay(c.columnName));
|
|
6645
|
+
const byDisplay = columns.findIndex((c) => isNumDisplay(c.displayColumnName));
|
|
6646
|
+
const byColumnName = columns.findIndex((c) => isNumDisplay(c.columnName));
|
|
6611
6647
|
const i = byDisplay !== -1 ? byDisplay : byColumnName;
|
|
6612
6648
|
return i; // -1 si no hay numeración
|
|
6613
6649
|
})(); // Detecta la columna de numeración ("", "N°" o "Nº") si existe
|
|
@@ -6618,7 +6654,7 @@ class HtmlToExcelService {
|
|
|
6618
6654
|
indentColIdx = numberColIdx + 1;
|
|
6619
6655
|
}
|
|
6620
6656
|
else {
|
|
6621
|
-
const nameIdx = columns.findIndex(c => (c.columnName ?? "").trim().toLowerCase() === "name" ||
|
|
6657
|
+
const nameIdx = columns.findIndex((c) => (c.columnName ?? "").trim().toLowerCase() === "name" ||
|
|
6622
6658
|
(c.displayColumnName ?? "").trim().toLowerCase().includes("name"));
|
|
6623
6659
|
if (nameIdx !== -1)
|
|
6624
6660
|
indentColIdx = nameIdx;
|
|
@@ -6627,7 +6663,7 @@ class HtmlToExcelService {
|
|
|
6627
6663
|
const rowValues = [];
|
|
6628
6664
|
for (let colIndex = 0; colIndex < columns.length; colIndex++) {
|
|
6629
6665
|
if (hasNumbering && colIndex === numberColIdx) {
|
|
6630
|
-
rowValues.push(isHierarchical ? rows[rowIndex].__hier :
|
|
6666
|
+
rowValues.push(isHierarchical ? rows[rowIndex].__hier : rowIndex + 1);
|
|
6631
6667
|
}
|
|
6632
6668
|
else {
|
|
6633
6669
|
rowValues.push(rows[rowIndex][columns[colIndex].columnName] ?? "");
|
|
@@ -6648,7 +6684,9 @@ class HtmlToExcelService {
|
|
|
6648
6684
|
};
|
|
6649
6685
|
});
|
|
6650
6686
|
// Indentación: si hay jerarquía y hay columna definida para indentar
|
|
6651
|
-
if (isHierarchical &&
|
|
6687
|
+
if (isHierarchical &&
|
|
6688
|
+
indentColIdx !== null &&
|
|
6689
|
+
indentColIdx < columns.length) {
|
|
6652
6690
|
const indentCell = insertedRow.getCell(indentColIdx + 1); // 1-based
|
|
6653
6691
|
indentCell.alignment = {
|
|
6654
6692
|
...(indentCell.alignment ?? {}),
|
|
@@ -6657,7 +6695,7 @@ class HtmlToExcelService {
|
|
|
6657
6695
|
}
|
|
6658
6696
|
}
|
|
6659
6697
|
//Formato nombre de columnas
|
|
6660
|
-
columnsCell.forEach(cellRef => {
|
|
6698
|
+
columnsCell.forEach((cellRef) => {
|
|
6661
6699
|
const cell = worksheet.getCell(cellRef);
|
|
6662
6700
|
cell.fill = {
|
|
6663
6701
|
type: "pattern",
|
|
@@ -6678,7 +6716,7 @@ class HtmlToExcelService {
|
|
|
6678
6716
|
if (rowIndex < firstDataRow)
|
|
6679
6717
|
return;
|
|
6680
6718
|
const isEven = (rowIndex - firstDataRow) % 2 === 0;
|
|
6681
|
-
row.eachCell(cell => {
|
|
6719
|
+
row.eachCell((cell) => {
|
|
6682
6720
|
if (!isEven) {
|
|
6683
6721
|
cell.fill = {
|
|
6684
6722
|
type: "pattern",
|
|
@@ -6731,12 +6769,12 @@ class HtmlToExcelService {
|
|
|
6731
6769
|
let widtFilter = 30;
|
|
6732
6770
|
worksheetFilter.addRow([filterTitle]);
|
|
6733
6771
|
worksheetFilter.mergeCells(["A1", "B2"]);
|
|
6734
|
-
worksheetFilter.columns.forEach(column => {
|
|
6772
|
+
worksheetFilter.columns.forEach((column) => {
|
|
6735
6773
|
column.width = widtFilter;
|
|
6736
6774
|
column.alignment = this.ColumnAligment;
|
|
6737
6775
|
widtFilter *= 3;
|
|
6738
6776
|
});
|
|
6739
|
-
["A1", "B1"].map(key => {
|
|
6777
|
+
["A1", "B1"].map((key) => {
|
|
6740
6778
|
worksheetFilter.getCell(key).fill = {
|
|
6741
6779
|
type: "pattern",
|
|
6742
6780
|
pattern: "solid",
|
|
@@ -6753,7 +6791,7 @@ class HtmlToExcelService {
|
|
|
6753
6791
|
filters.forEach((element, index) => {
|
|
6754
6792
|
let row = worksheetFilter.addRow([element.key, element.value]);
|
|
6755
6793
|
let color = index % 2 === 1 ? "D9D9D9" : "FFFFFF";
|
|
6756
|
-
row.eachCell(cell => {
|
|
6794
|
+
row.eachCell((cell) => {
|
|
6757
6795
|
cell.fill = {
|
|
6758
6796
|
type: "pattern",
|
|
6759
6797
|
pattern: "solid",
|
|
@@ -6775,7 +6813,10 @@ class HtmlToExcelService {
|
|
|
6775
6813
|
return;
|
|
6776
6814
|
if (columns[index] == undefined)
|
|
6777
6815
|
return;
|
|
6778
|
-
let columnWidth = columns[index].width ??
|
|
6816
|
+
let columnWidth = columns[index].width ??
|
|
6817
|
+
Math.max(...column.values
|
|
6818
|
+
.map((v) => (v ? v.toString().length : 0))
|
|
6819
|
+
.filter((v) => typeof v === "number"), columns[index].displayColumnName.length) * 1.4;
|
|
6779
6820
|
column.width = Math.min(Math.max(columnWidth, 5), 100);
|
|
6780
6821
|
});
|
|
6781
6822
|
worksheet.eachRow((row, rowIndex) => {
|
|
@@ -6784,7 +6825,9 @@ class HtmlToExcelService {
|
|
|
6784
6825
|
let maxLines = 1;
|
|
6785
6826
|
row.eachCell((cell, colNumber) => {
|
|
6786
6827
|
if (cell.value) {
|
|
6787
|
-
let text = typeof cell.value === "object"
|
|
6828
|
+
let text = typeof cell.value === "object"
|
|
6829
|
+
? cell.text
|
|
6830
|
+
: cell.value.toString();
|
|
6788
6831
|
let columnWidth = worksheet.getColumn(colNumber).width ?? 10;
|
|
6789
6832
|
let charsPerLine = columnWidth * 1.2;
|
|
6790
6833
|
let estimatedLines = Math.ceil(text.length / charsPerLine);
|
|
@@ -6794,12 +6837,14 @@ class HtmlToExcelService {
|
|
|
6794
6837
|
row.height = Math.min(Math.max(15 * maxLines, 15), 30);
|
|
6795
6838
|
});
|
|
6796
6839
|
}
|
|
6797
|
-
async ExportToExcelRawData({ excelName, reportTitle, filterTitle, rowsSerializate, columns, filters, orderColumn = false }) {
|
|
6840
|
+
async ExportToExcelRawData({ excelName, reportTitle, filterTitle, rowsSerializate, columns, filters, orderColumn = false, }) {
|
|
6798
6841
|
const workbook = new Workbook();
|
|
6799
6842
|
const worksheet = workbook.addWorksheet(reportTitle);
|
|
6800
6843
|
const rows = JSON.parse(rowsSerializate);
|
|
6801
6844
|
worksheet.views = [{ showGridLines: false }];
|
|
6802
|
-
const allColumns = orderColumn
|
|
6845
|
+
const allColumns = orderColumn
|
|
6846
|
+
? [{ displayColumnName: "N°" }, ...columns]
|
|
6847
|
+
: columns;
|
|
6803
6848
|
allColumns.forEach((col, index) => {
|
|
6804
6849
|
const columnLetter = this.GetExcelColumnLetter(index);
|
|
6805
6850
|
const headerCell = worksheet.getCell(`${columnLetter}1`);
|
|
@@ -6807,14 +6852,14 @@ class HtmlToExcelService {
|
|
|
6807
6852
|
headerCell.alignment = { horizontal: "center", vertical: "middle" };
|
|
6808
6853
|
headerCell.font = { name: "Arial", bold: true, size: 10 };
|
|
6809
6854
|
});
|
|
6810
|
-
const maxLengths = allColumns.map(col => col.displayColumnName.length);
|
|
6855
|
+
const maxLengths = allColumns.map((col) => col.displayColumnName.length);
|
|
6811
6856
|
rows.forEach((rowData, rowIndex) => {
|
|
6812
6857
|
const rowValues = allColumns.map((col, colIndex) => {
|
|
6813
6858
|
if (orderColumn && colIndex === 0) {
|
|
6814
|
-
return
|
|
6859
|
+
return rowIndex + 1;
|
|
6815
6860
|
}
|
|
6816
6861
|
const originalColIndex = orderColumn ? colIndex - 1 : colIndex;
|
|
6817
|
-
return rowData[columns[originalColIndex].columnName]?.toString() || "";
|
|
6862
|
+
return (rowData[columns[originalColIndex].columnName]?.toString() || "");
|
|
6818
6863
|
});
|
|
6819
6864
|
rowValues.forEach((value, i) => {
|
|
6820
6865
|
const length = value.length;
|
|
@@ -6837,9 +6882,11 @@ class HtmlToExcelService {
|
|
|
6837
6882
|
}
|
|
6838
6883
|
async ExportToCSVRaw(excelName, rowsSerializate) {
|
|
6839
6884
|
const rows = JSON.parse(rowsSerializate);
|
|
6840
|
-
const csvLines = rows.map(r => r.linea);
|
|
6885
|
+
const csvLines = rows.map((r) => r.linea);
|
|
6841
6886
|
const csvContent = csvLines.join("\n");
|
|
6842
|
-
const blob = new Blob(["\uFEFF" + csvContent], {
|
|
6887
|
+
const blob = new Blob(["\uFEFF" + csvContent], {
|
|
6888
|
+
type: "text/csv;charset=utf-8;",
|
|
6889
|
+
});
|
|
6843
6890
|
saveAs(blob, excelName.endsWith(".csv") ? excelName : `${excelName}.csv`);
|
|
6844
6891
|
}
|
|
6845
6892
|
GetExcelColumnLetter(columnNumber) {
|
|
@@ -6870,7 +6917,7 @@ class HtmlToExcelService {
|
|
|
6870
6917
|
...copy,
|
|
6871
6918
|
__hier: seq.join("."), // "1" | "1.1" | "2.2.1" ...
|
|
6872
6919
|
__level: seq.length - 1, // 0 = raíz, 1 = hijo, 2 = nieto...
|
|
6873
|
-
__hasChildren: hasChildren // para formateo en negrita
|
|
6920
|
+
__hasChildren: hasChildren, // para formateo en negrita
|
|
6874
6921
|
});
|
|
6875
6922
|
if (hasChildren) {
|
|
6876
6923
|
flat.push(...this.FlattenRowsForHierarchy(item[childKey], childKey, seq));
|
|
@@ -6879,7 +6926,7 @@ class HtmlToExcelService {
|
|
|
6879
6926
|
return flat;
|
|
6880
6927
|
}
|
|
6881
6928
|
DetectsHierarchy(rows, childKey = "details") {
|
|
6882
|
-
return rows?.some(r => Array.isArray(r?.[childKey]) && r[childKey].length > 0) ?? false;
|
|
6929
|
+
return (rows?.some((r) => Array.isArray(r?.[childKey]) && r[childKey].length > 0) ?? false);
|
|
6883
6930
|
}
|
|
6884
6931
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: HtmlToExcelService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
6885
6932
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: HtmlToExcelService, providedIn: "root" });
|