#Generate excel file in remix

1 messages · Page 1 of 1 (latest)

eternal plank
#

I'm currently dealing with an issue in generating Excel files in Remix. My requirement is to trigger a backend loader to query data from the database, process it, and then generate an Excel file when a user clicks the 'Export' button. I am utilizing the 'xlsx' package to create the Excel file. However, I'm unable to figure out how to temporarily store the generated file, delete it post-response, and return a response to the client. I'm attaching a screenshot of the code snippets for reference. Thanks you all

eternal plank
#

@livid tiger @pine shoal

livid tiger
#

So I looked at the code in the screenshot. It appears to be writing to a temp file then sending the file in the response. Are you not able to do that in your app?

I looked at the API for XLSX (now sheetjs), and there is a XLSX.write function that allows you to return a Buffer that can be sent as your response.

const buffer = XSLX.write(workBook, { bookType: 'xlsx', type: 'buffer' })
const headers = { ... }
return new Response(buffer, { headers })

https://docs.sheetjs.com/docs/api/write-options