8

I am trying to implement export to excel with React and SheetJs library. Looks like I can download it, but the actual output does not look as expected. I receive array of object and use XLSX.utils.json_to_sheet([data]) API to converts an array of JS objects to a worksheet. Problem is : enter image description here

I've reproduced it here

Sergey
  • 995
  • 4
  • 14
  • 33
Palaniichuk Dmytro
  • 2,943
  • 12
  • 36
  • 66

1 Answers1

6

Fixed here: https://stackblitz.com/edit/react-yg6pt5?file=exportToExcel.js

Bug was with XLSX.utils.json_to_sheet([data]) XLSX.utils.json_to_sheet(data) this utils use object of array as aurgument instead array of objects

Change wb.SheetNames.push(''); wb.Sheets[''] = ws to wb.SheetNames.push('sheet1'); wb.Sheets['sheet1'] = ws so that you will not get data recovery error while opening file

Ashu
  • 2,066
  • 3
  • 19
  • 33
Palaniichuk Dmytro
  • 2,943
  • 12
  • 36
  • 66