Write Data to an Excel Template and save it as a New file in Retool storage

Hey there,

I need assistance with writing a Data Frame to an Excel template file stored in Retool storage. The template is saved in Retool, and I want to write the Data Frame to this template without modifying the original file. Specifically, I’d like to:

  1. Open the Excel template from Retool storage.
  2. Write the Data Frame to the template.
  3. Save the modified file as a new, separate Excel file in Retool storage, ensuring the original template remains unchanged.

Is this doable, and anyone have any idea on how to achieve it?

Thank you in advance for your help!

Hey there,
Just wanted to check if the above mentioned is doable ?

should be possible. i think the easiest way would be to add https://cdn.jsdelivr.net/npm/danfojs@1.1.2/lib/bundle.min.js as a library then you can use dfd.toExcel(). docs are over here

you could also use retool storage resource and read file contents. then in a js query create a new file w .xls extenstion (or whatever excel is). open a file stream with write permissions and then you can copy over the file contents you read earlier.

Got it! Thanks for the reply!!
But I am having trouble with opening the template file. I would like to open the template file from the retool storage location and write data to it but not save it. I want to save that as a different file in same location so my template is not disturbed !!

I would really appreciate if any screenshot are provided to guide me here!!

is this what you're trying to do? this will read the content of a file in retool storage, then it uses what it read to upload a new file to retool storage. it uses the same name, so the uploaded file in my case was logo(1).svg. you can use Transform results from query22 if you want to make modifications to the file contents after getting a copy of the file. to do this you'd need to decode the base64 into an object then make changes, re-encode, then you can upload the new modified base64 string to retool storage like query23... I'd suggest using the library for any file content manipulation

My actual goal is, I have a Excel file in Retool storage and it has few complex formulas in the all the columns of Sheet2. So, when I write the data from my SQL table to Sheet1 the formulas will be auto executed in the Sheet2.

In Retool I want to achieve something like that!. Once I write data to the Sheet1 of my Excel file template I want to re-upload that to Retool storage as a new file but my original file template will remain the same with no data, so that I can use the same template again for different data.

Hey there,
Is the above is something doable in Retool?
I just want to be able to open up the file stored in Retool storage using Js or Python code, just like how we open up the file from local storage using a code.

Hi @Jonas_Dylan,

  1. Use @bobthebear's query to get the file:
  1. Use the library he shared to make changes to the downloaded file (this will be a copy, the original won't be modified):
  1. Use this query to upload the new -modified- file, if you don't enable "Overwrite existing file with same name," the original won't be overwritten: