diff --git a/HRM.UI/ClientApp/src/app/common-interface/data-upload/data-upload.component.ts b/HRM.UI/ClientApp/src/app/common-interface/data-upload/data-upload.component.ts index fd77c72..6b53f60 100644 --- a/HRM.UI/ClientApp/src/app/common-interface/data-upload/data-upload.component.ts +++ b/HRM.UI/ClientApp/src/app/common-interface/data-upload/data-upload.component.ts @@ -30,6 +30,7 @@ import { TaxInvestment } from "../../_models/Payroll/Tax/taxInvestment"; import { AttendanceServices } from "../../_services/attendance/attendance.service"; import * as fileSaver from "file-saver"; import * as XLSX from "xlsx"; +import * as ExcelJS from "exceljs"; import { TaxParameter } from "../../_models/Payroll/Tax/taxParameter"; import { OpiService } from "../../_services/payroll/opi.service"; import { OpiItem } from "../../_models/Payroll/opiItem"; @@ -1016,15 +1017,32 @@ export class DataUploadComponent implements OnInit, OnDestroy { //const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] }; //new - const workbook = XLSX.utils.book_new(); - const workSheet = XLSX.utils.json_to_sheet(cols); - XLSX.utils.book_append_sheet(workbook, workSheet, this.sheetName); + //const workbook = XLSX.utils.book_new(); + //const workSheet = XLSX.utils.json_to_sheet(cols); + //XLSX.utils.book_append_sheet(workbook, workSheet, this.sheetName); + //const excelBuffer: any = XLSX.write(workbook, { + // bookType: "xlsx", + // type: "array", + //}); + //this.saveAsExcelFile(excelBuffer, this.sheetName); - const excelBuffer: any = XLSX.write(workbook, { - bookType: "xlsx", - type: "array", + // Same sheet name, same header row in the same order and same file name as before; the only + // difference is that mandatory columns (allowNull = "NO", the ones shown red on the page) get a + // red header. Built with exceljs because the community xlsx build cannot write cell colours. + const workbook = new ExcelJS.Workbook(); + const workSheet = workbook.addWorksheet(this.sheetName); + const headerRow = workSheet.addRow(this.test.columnName); + this.test.columnName.forEach((col, index) => { + const allowNull: string = this.test.allowNull ? this.test.allowNull[index] : null; + const mandatory = !!allowNull && allowNull.toUpperCase() == "NO"; + // every header bold; mandatory ones also red + headerRow.getCell(index + 1).font = mandatory ? { bold: true, color: { argb: "FFFF0000" } } : { bold: true }; + // each column as wide as its own header text (+ a little room for bold text) + workSheet.getColumn(index + 1).width = Math.max(String(col ?? "").length + 4, 8); + }); + workbook.xlsx.writeBuffer().then((excelBuffer: any) => { + this.saveAsExcelFile(excelBuffer, this.sheetName); }); - this.saveAsExcelFile(excelBuffer, this.sheetName); } } diff --git a/HRM.UI/ClientApp/src/app/payroll/career-and-profile/employee-cost-center-entry/employee-cost-center-entry.component.css b/HRM.UI/ClientApp/src/app/payroll/career-and-profile/employee-cost-center-entry/employee-cost-center-entry.component.css index b520973..bc60dad 100644 --- a/HRM.UI/ClientApp/src/app/payroll/career-and-profile/employee-cost-center-entry/employee-cost-center-entry.component.css +++ b/HRM.UI/ClientApp/src/app/payroll/career-and-profile/employee-cost-center-entry/employee-cost-center-entry.component.css @@ -1,7 +1,9 @@ -/* Required-field marker on the fields themselves. Not on wrapper