Hey @hrishikesh,
the last days I tried it the way…
…sending a
base64
string to the browser and convertbase64
toblob
on the client-side and allow users to download thatblob
IT WORKS!
Your way with that binary is shorter and can be done without any client logic, just with a link - NICE!
I copy that code here, so you can delete your repo.
import Express, {Router} from 'express'
import Serverless from 'serverless-http'
import {fromFileAsync as Xlsx} from 'xlsx-populate'
export async function handler(event, context) {
const app = Express()
const router = Router()
router.get('/', (request, response) => {
Xlsx('./file_example.xlsx').then(workbook => {
const sheet = workbook.sheet('Sheet1')
const params = request.query
Object.keys(params).map((key, index) => {
sheet.cell(key).value(Object.values(params)[index])
})
return workbook.outputAsync()
}).then(data => {
response.attachment('output.xlsx')
response.send(data)
})
})
app.use('/.netlify/functions/api', router)
return Serverless(app, {
binary: ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
})(event, context).then(result => {
return result
})
}
Thank you very much for your support!
Greetings from germany - Michael