ReferenceError: ExcelJS is not defined

Hi,
Need a bit help here, I am very much new to Retool and Js. I am trying to execute the Js code in the workflow but every time it gives me error with msg: ReferenceError: ExcelJS is not defined (line 2). Not sure how to import/define ExcelJS module. Any idea how to resolve this ?
Below is the code I am trying to run.

async function exportData() { 
  const workbook = new ExcelJS.Workbook();
  const sheet = workbook.addWorksheet('My Sheet');

  sheet.addTable({
    name: 'MyTable',
    ref: 'A1',
    style: { theme: 'TableStyleDark3', showRowStripes: true },
    columns: [{ name: 'Date' }, { name: 'Amount' }],
    rows: [
      [new Date('2019-07-20'), 70.10],
      [new Date('2019-07-21'), 70.60],
      [new Date('2019-07-22'), 70.10],
    ],
  });
 
  const buffer = await workbook.xlsx.writeBuffer()
  utils.downloadFile({ base64Binary: buffer.toString('base64')}, "file-name", "xlsx")
}
 
return exportData()

Thanks in advance for any help !!

Hi @Jonas_Dylan,

You an import the library and use it like this:

From your workflow, click the libraries button, then the + to add a library.

Search for exceljs and check the box next to it. That'll make it available. Then in your code, add the following to the top (above your function in this case)

const ExcelJS = require('exceljs');

That should make it available.

1 Like