Add Multiple Sheets to Exported xlsx

Hello, I succeeded to download an Excel file with multiple sheets within a query using the utils.downloadFile function like this:

const data = [
  { name: "John", city: "Seattle" },
  { name: "Mike", city: "Los Angeles" },
  { name: "Zach", city: "New York" },
];
const sheet = XLSX.utils.json_to_sheet(data);

const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, sheet, "People1");
XLSX.utils.book_append_sheet(workbook, sheet, "People2");

const result = XLSX.write(workbook, { type: "base64" });

utils.downloadFile({ base64Binary: result }, "people", "xlsx");

Note that this requires that you have added the xlsx library in preloaded libraries, for example using the unpkg CDN

2 Likes