Every table offers a "download as CSV" button.
On mac I can just download and then open with Excel and the data looks correct.
But on windows this does not work.
I figured out that there is the JS function utils.exportData(table.data, 'filename', 'csv')
I figured out that instead of csv I can also put tsv, but this also doesn't work. Is it possible to specify Excel as a format?
Hi No I meant can you specify what the sheet would be called within the file. For example when you open a new Excel file workbook, the sheet name by default is Sheet1. Can we send an option to do this via the code above with an additional option? Also, the image above for Option 2 has "Sheet name" as an option. But how do you specify that in code?
Ah, in code that's not as directly possible. You'd need to first specify that sheet name in a Google Sheets query by either typing it in directly, or dynamically! And then you can export the data from that query using the JS function.
Does this help get you any closer at all? Either way, let me know!
Okay, I am actually using Excel, not Google sheets (are they interchangeable?) Anyways, yes I do have the filenames, sheet names, source queries all ready to go, but just trying to figure out a way to export them all into an Excel object (one query result per Excel worksheet) and then when all done, download the Excel file with the pre specified name. My main issue I am trying to solve with this is I have my database in Snowflake and need to export some queries from there into a Single Excel fie so I can then load that single Excel file into a 3rd party program. Have the Retool tool completely built for this and it works excellently! EXCEPT for this very last piece of functionality.
Here's an example of my code for one of the queries and one of sheets of the file that I am trying to create and export (download).
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)
};
wb.SheetNames.push("BA");
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')
Thank you for sharing that! There is no native way to set the specific sheet name with JS in Retool, but you can add a sheet name inside of an event handler directly.
Regarding your specific query, is everything working except that very last line? And just to double check that last line, does your XLSX library can call a utils.openUrl function, or are you attempting to use the Retool function utils.openUrl?