1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How Angular Export to Excel with formatting cell?

Discussão em 'Angular' iniciado por 0917237, Outubro 1, 2024 às 03:42.

  1. 0917237

    0917237 Guest

    My Excel Service with method exportAsExcelFile:

    public exportAsExcelFile(json: any[], excelFileName: string): void {
    const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
    const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
    const excelBuffer: any = XLSX.write(workbook, { bookType: 'xls', type: 'array' });
    this.saveAsExcelFile(excelBuffer, excelFileName);
    }

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


    my Component with method exportDataToExcel() :

    dataToExport: any = [];
    exportFileName: string = "TRANSACTION_HISTORY_REPORT";


    exportDatatoExcel(){

    this.myAPIService.getData().then(
    (data) => {

    data.forEach((data, index) => {

    this.dataToExport.push({
    no: index + 1,
    total_item_sold: data.detailItem.length,
    total_price: data.totalPrice,

    });
    });

    if(this.dataToExport.length > 0){
    if(this.exportFileName == "") this.exportFileName = "default";
    this.excelService.exportAsExcelFile(this.dataToExport,
    this.exportFileName);
    }
    }
    );

    }


    How to Export that json total_price with formatting Accounting cell in Excel?

    Continue reading...

Compartilhe esta Página