Answers for "xlsx.utils.json_to_sheet example"

0

xlsx.utils.json_to_sheet example

const ExportCSV = ({csvData, fileName}) => {

  const fileType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
  const fileExtension = '.xlsx';

  const exportToCSV = (csvData, fileName) => {
    const ws = XLSX.utils.json_to_sheet(csvData);
    const wb = { Sheets: { 'data': ws }, SheetNames: ['data'] };
    const excelBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
    const data = new Blob([excelBuffer], {type: fileType});
    FileSaver.saveAs(data, fileName + fileExtension);
  }

  return (
    <Button variant="warning" onClick={(e) => exportToCSV(csvData,fileName)}>Export</Button>
  )
}
Posted by: Guest on August-10-2021

Browse Popular Code Answers by Language