Export multiple query(x).data results in multiple sheets(x) to single Excel file

I realize this message is out here on How do I export multiple sheets to a single Excel file, but this doesn't quite seem to work. Does anyone have a proven way of having multiple query results (a.k.a. query1.data, query2.data, query3.data, etc.) being exported off in sheets named query1, query2, query3, etc. (or whatever) to a single Excel file (preferably an existing Excel file, but a brand new one would work as well? I have installed the SheetJs (XLSX) and FilesaverJs libraries, but having zero luck so far. Any help or steer in the right direction would be much appreciated.


Hey there :wave: Would you mind sharing a screenshot of how you are currently attempting this? I would assume with utils.downloadFile?

This is what I have so far, but not exactly working.

            var wb = XLSX.utils.book_new();
        	wb.Props = {
                Title: textInputEnCompassFileName.value,
                Subject: 'Power Dispatch EnCompass Input File',
                Author: userNameFirst + ' ' + userNameLast,
                CreatedDate: new Date(year,month,day)
            var ws_data = SELECT_BA.data;
            var ws = XLSX.utils.aoa_to_sheet(ws_data);
            wb.Sheets["BA"] = ws;
            var wbout = XLSX.write(wb, {bookType:'xlsx',  type: 'binary'})
            XLSX.utils.downloadFile(ws_data, textInputEnCompassFileName.value, '.xlsx')

Hey Orennia!

I was able to get @aturiots code to work for me, do you get any errors when running their example code?

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");

Yes @Chris-Thompson this worked for me. Finally getting around to implementing this. I think I was attempting to use the incorrect library. This one: https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.2/xlsx.min.js did the trick! Thanks again!!!