Upload Excel file to Retool storage or Sharepoint link

Hi there,
I am currently working on Retool to build an application. So, the functionality of the app will be as follows:

I will be executing a Snowflake store procedure. This will create 4 to 5 temporary tables and I need these tables data in CSV format and stored in some dedicated location either in SharePoint folder or in Retool storage in a folder.

If possible I need data in different sheets in one excel instead of multiple CSV files.

Not sure, If the above is doable and need some guidance here.

Thanks in advance for any help !!

Hi @Jonas_Dylan, welcome to the community :wave:

This is doable. have a look at this thread. There's a library in js that we use to add multiple sheets to a single excel file. I'm not sure if you want this in workflow or in an app but you can simply follow that code by arturiot. If you encounter any specific issue, post a follow-up here.

Hey @jocen Thanks for the reply !!
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 ?

Hey @Jonas_Dylan, yep. On the left-hand side, you can look at the library tab (see image below):

Not sure if ExcelJS is available in the js libraries in workflows but you can use xlsx. You can refer to the tagged solution for implementation of it. Alternatively, you can check this one for implementation of it:

Make sure you are assigning array of objects when creating a table/sheet. In the example above, your data should be:

  field1: 1,
  field2: "John",
  field3: "Doe",
  field4: 26, ...
}, ...]

Hope that helps break it down a bit for you.

Hey @jocen
Thanks for the Help !!
It worked for me, the code executed and returned an Object string. Just want to understand how do I use this Object string to download the file ? or Is it already downloaded at some place ?
It would be really great if the file could be downloaded to Retool storage in a specific folder since this is my actual use case that I want to achieve here.

Hope you have any idea to achieve this !!

Hey @Jonas_Dylan, it's not yet downloaded. If you want this stored in Retool storage, you can cut back a bit on the step there in the sample code as retool storage upload function only requires you to add a base64 string of the file (refer to image below):

I know that view is in the apps but the input field would be similar in workflows. In the File Content area, you can use the returned data from the javascript code for it. But again, you need to adjust the code to only returning the file's base64 string, i.e. if we're referring to the createFile example above

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

return result

adjust it as well to be an xlsx file in the File Name, i.e. daily_file_20240620.xlsx. It will appear as a File Type in Retool Storage but once you download it, it'll be an xlsx file.

1 Like

Hey @jocen Thanks for the help!!
I could finally achieve what I wanted. So, I was trying to figure out a way to programmatically create new folder in Retool using some variable in my code and save the file in that folder. Is this doable ?

You can find the solution to your question here.

1 Like