Search code examples
excelangularnpmxlsxexceljs

How to import desgin of an Excel Template in Angular as Object


I want to Import data from Excel, after modification i want to export the updated data.

I am able to import data from Excel file using XLSX package, but while i export the new data, all the styling is gone.

I want persist the Design/Style/Theme of the excel while exporting.

// For Import
  importExcel(e) {
    const bstr: string = e.target.result;
    const wb: XLSX.WorkBook = XLSX.read(bstr, { type: 'binary' });
    const wsname: string = wb.SheetNames[0];
    const ws: XLSX.WorkSheet = wb.Sheets[wsname];
    return of(<AOA>(XLSX.utils.sheet_to_json(ws, { header: 1,  })));
  }

// for Export of File   
  exportAsExcelFile(data: any[]): void {
    const ws: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet(data);
    const wb: XLSX.WorkBook = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
    XLSX.writeFile(wb, this.fileName);
  }

i want to persist the design of excel template

Solution

  • xlsx is package available on NPM by sheetJS. They provide template export only in their pro-version.

    you can use exceljs instead. this is also available over npm

    check How to import EXCEL file in angular using exceljs for reading a excelfile in angular using exceljs