Skip to content

Corrupt xlsx file #1920

@ingermaa

Description

@ingermaa

Im getting Corrupt excel file while opening the file in Excel.

Code:

private saveAsExcelFile(buffer: any, fileName: string): void {
  const data: Blob = new Blob([buffer], {
    type: EXCEL_TYPE
  });
  saveAs.saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION);
}

  public exportAsExcelFile(table:any, excelFileName: string): void {
    const readyToExport = [
      { id: 1, name: 'a' },
      { id: 2, name: 'b' },
      { id: 3, name: 'c' }
    ];

    const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(readyToExport);
    const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
    const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'buffer' });
    this.saveAsExcelFile(excelBuffer, excelFileName);

    return;

}

The exported xlsx file starts with:

PK��
     "]�PÖ�|�Z�  Z�  �   docProps/core.xml<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Version: 0.15.6
Excel version: 365MSO (16.0.12624.20422)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions