merge angular-17 into dev to upgrade from Angular v16 to v17
This commit is contained in:
@@ -13,7 +13,7 @@ import { SelectOption } from '../common-models/select-option.model';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { GlobalConfiguration } from 'app/system/configurations/global-configurations-tab/configuration.model';
|
||||
|
||||
import * as XLSX from 'xlsx';
|
||||
import * as ExcelJS from 'exceljs';
|
||||
import { AlertService } from 'app/core/alert/alert.service';
|
||||
|
||||
/**
|
||||
@@ -251,7 +251,7 @@ export class RunReportComponent implements OnInit {
|
||||
formattedResponse[newKey] = value;
|
||||
break;
|
||||
case 'select':
|
||||
formattedResponse[newKey] = value['id'];
|
||||
formattedResponse[newKey] = (value as { id: string | number })['id'];
|
||||
break;
|
||||
case 'date':
|
||||
if (this.isTableReport()) {
|
||||
@@ -339,18 +339,46 @@ export class RunReportComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
exportToXLS(reportName: string, csvData: any, displayedColumns: string[]): void {
|
||||
async exportToXLS(reportName: string, csvData: any, displayedColumns: string[]): Promise<void> {
|
||||
const fileName = `${reportName}.xlsx`;
|
||||
|
||||
// Format data for ExcelJS
|
||||
const data = csvData.map((object: any) => {
|
||||
const row = {};
|
||||
const row: Record<string, any> = {};
|
||||
for (let i = 0; i < displayedColumns.length; i++) {
|
||||
row[displayedColumns[i]] = object.row[i];
|
||||
}
|
||||
return row;
|
||||
});
|
||||
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(data, { header: displayedColumns });
|
||||
const wb: XLSX.WorkBook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(wb, ws, 'report');
|
||||
XLSX.writeFile(wb, fileName);
|
||||
|
||||
// Create workbook and worksheet
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const worksheet = workbook.addWorksheet('report');
|
||||
|
||||
// Add header
|
||||
worksheet.addRow(displayedColumns);
|
||||
|
||||
// Add data rows
|
||||
data.forEach((rowObj: any) => {
|
||||
worksheet.addRow(displayedColumns.map((col) => rowObj[col]));
|
||||
});
|
||||
|
||||
// Write to buffer and trigger download
|
||||
const buffer = await workbook.xlsx.writeBuffer();
|
||||
const blob = new Blob([buffer], {
|
||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
});
|
||||
|
||||
// Native download logic (no FileSaver)
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.componen
|
||||
import { environment } from 'environments/environment';
|
||||
import { ProgressBarService } from 'app/core/progress-bar/progress-bar.service';
|
||||
|
||||
import * as XLSX from 'xlsx';
|
||||
import * as ExcelJS from 'exceljs';
|
||||
|
||||
/**
|
||||
* Table and SMS Component
|
||||
@@ -143,16 +143,33 @@ export class TableAndSmsComponent implements OnChanges {
|
||||
exportToXLS(): void {
|
||||
const fileName = `${this.dataObject.report.name}.xlsx`;
|
||||
const data = this.csvData.map((object: any) => {
|
||||
const row = {};
|
||||
const row: { [key: string]: any } = {};
|
||||
for (let i = 0; i < this.displayedColumns.length; i++) {
|
||||
row[this.displayedColumns[i]] = object.row[i];
|
||||
}
|
||||
return row;
|
||||
});
|
||||
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(data, { header: this.displayedColumns });
|
||||
const wb: XLSX.WorkBook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(wb, ws, 'Report');
|
||||
XLSX.writeFile(wb, fileName);
|
||||
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const worksheet = workbook.addWorksheet('Report');
|
||||
|
||||
// Add header row
|
||||
worksheet.addRow(this.displayedColumns);
|
||||
|
||||
// Add data rows
|
||||
data.forEach((rowObj: any) => {
|
||||
worksheet.addRow(this.displayedColumns.map((col) => rowObj[col]));
|
||||
});
|
||||
|
||||
workbook.xlsx.writeBuffer().then((buffer: any) => {
|
||||
const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'filename.xlsx';
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user