0

I'm using XLSX and alasql to export json object in to excel getting workbook is empty error, how to resolve

import * as alasql from 'alasql'
import * as XLSX from 'xlsx'

alasql.utils.isBrowserify = false
alasql.utils.global.XLSX = XLSX


const fileName = 'Ticket Details ' + props.ticketNumber
alasql('SELECT INTO XLSX("' + fileName + '.xlsx",?) FROM ?', [opts, finalData])
KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133

1 Answers1

0

After debugging the code I got to know my finalData Array is empty, then I corrected the array value

Solution:

import * as alasql from 'alasql'
import * as XLSX from 'xlsx'

alasql.utils.isBrowserify = false
alasql.utils.global.XLSX = XLSX

const finalData = [
    {name:"John", city: "Seattle"},
    {name:"Mike", city: "Los Angeles"},
    {name:"Zach", city: "New York"}
]
const fileName = 'Ticket Details ' + props.ticketNumber
alasql('SELECT INTO XLSX("' + fileName + '.xlsx",?) FROM ?', [opts, finalData])
KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133