Skip to content

Commit 6fa3972

Browse files
Update dependencies to fix vulnerabilities and migrate xlsx to exceljs
Co-authored-by: granatonatalia <[email protected]>
1 parent 5d2e7bb commit 6fa3972

File tree

2 files changed

+50
-12
lines changed

2 files changed

+50
-12
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,22 @@
2828
"@grafana/faro-web-tracing": "^1.12.2",
2929
"@ngneat/until-destroy": "^10.0.0-beta.0",
3030
"d3": "^7.5.0",
31+
"exceljs": "^4.4.0",
3132
"js-yaml": "^4.1.1",
3233
"markdown-it": "^13.0.1",
3334
"rxjs": "~7.5.0",
3435
"tslib": "^2.8.1",
35-
"xlsx": "^0.18.5",
3636
"yaml": "^2.8.1",
3737
"yamljs": "^0.3.0",
3838
"zone.js": "~0.11.4"
3939
},
4040
"devDependencies": {
4141
"@angular-devkit/build-angular": "^21.0.5",
42-
"@angular-eslint/builder": "^13.0.0",
43-
"@angular-eslint/eslint-plugin": "^13.0.0",
44-
"@angular-eslint/eslint-plugin-template": "^13.0.0",
42+
"@angular-eslint/builder": "^18.4.2",
43+
"@angular-eslint/eslint-plugin": "^18.4.2",
44+
"@angular-eslint/eslint-plugin-template": "^18.4.2",
4545
"@angular-eslint/schematics": "^21.1.0",
46-
"@angular-eslint/template-parser": "^13.0.0",
46+
"@angular-eslint/template-parser": "^18.4.2",
4747
"@angular/compiler-cli": "^13.0.0",
4848
"@grafana/faro-webpack-plugin": "^0.1.1",
4949
"@types/d3": "^7.4.0",

src/app/pages/mapping/mapping.component.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MatTableDataSource } from '@angular/material/table';
33
import { MatSort } from '@angular/material/sort';
44
import { COMMA, ENTER } from '@angular/cdk/keycodes';
55
import { FormControl } from '@angular/forms';
6-
import * as XLSX from 'xlsx';
6+
import * as ExcelJS from 'exceljs';
77
import { LoaderService } from 'src/app/service/loader/data-loader.service';
88
import {
99
DialogInfo,
@@ -157,12 +157,50 @@ export class MappingComponent implements OnInit, AfterViewInit {
157157
});
158158
}
159159

160-
exportToExcel() {
161-
let element = document.getElementById('excel-table');
162-
const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(element, { raw: true });
163-
const wb: XLSX.WorkBook = XLSX.utils.book_new();
164-
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
165-
XLSX.writeFile(wb, 'DSOMM - Activities.xlsx');
160+
async exportToExcel() {
161+
const element = document.getElementById('excel-table');
162+
if (!element) {
163+
console.error('Excel table element not found');
164+
return;
165+
}
166+
167+
const workbook = new ExcelJS.Workbook();
168+
const worksheet = workbook.addWorksheet('Sheet1');
169+
170+
// Extract table data from HTML table
171+
const table = element as HTMLTableElement;
172+
const rows = Array.from(table.querySelectorAll('tr'));
173+
174+
rows.forEach((row) => {
175+
const cells = Array.from(row.querySelectorAll('th, td'));
176+
const rowData = cells.map(cell => cell.textContent?.trim() || '');
177+
worksheet.addRow(rowData);
178+
});
179+
180+
// Auto-fit columns for better readability
181+
worksheet.columns.forEach(column => {
182+
let maxLength = 0;
183+
column.eachCell?.({ includeEmpty: true }, (cell) => {
184+
const cellLength = cell.value ? cell.value.toString().length : 10;
185+
if (cellLength > maxLength) {
186+
maxLength = cellLength;
187+
}
188+
});
189+
column.width = Math.min(maxLength + 2, 50); // Max width of 50
190+
});
191+
192+
// Generate and download the Excel file
193+
const buffer = await workbook.xlsx.writeBuffer();
194+
const blob = new Blob([buffer], {
195+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
196+
});
197+
const url = window.URL.createObjectURL(blob);
198+
const anchor = document.createElement('a');
199+
anchor.href = url;
200+
anchor.download = 'DSOMM - Activities.xlsx';
201+
anchor.click();
202+
window.URL.revokeObjectURL(url);
203+
166204
console.log(`${perfNow()}: Mapping: Exported to Excel`);
167205
}
168206

0 commit comments

Comments
 (0)