react-pivottable icon indicating copy to clipboard operation
react-pivottable copied to clipboard

Export Table as Excel File / PDF

Open ahmedhamza47 opened this issue 2 years ago • 2 comments

Hello I would like to export the table as excel file or as pdf. But I am not being able to do it. Can anyone help me with this issue. It would be really helpful!

ahmedhamza47 avatar Dec 11 '23 08:12 ahmedhamza47

I am also looking for the same as well. But not found how to do that

himanshu0911 avatar Feb 11 '24 05:02 himanshu0911

There is no inbuilt method to export data as excel file

const exportReport = () => { const pvtTable = document.getElementsByClassName('pvtTable'); const worksheet: XLSX.WorkSheet = XLSX.utils.table_to_sheet(pvtTable[0]); const workbook: XLSX.WorkBook = { Sheets: { data: worksheet }, SheetNames: ['data'], }; const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array', });

const data: Blob = new Blob([excelBuffer], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8',
});
FileSaver.saveAs(data, 'ExcelReport.xlsx');

}

create a button and onClick call this function . Make sure to install necessary package.

ahmedhamza47 avatar Feb 11 '24 05:02 ahmedhamza47