Reputation: 85
Documentations seems confusing to me. How can i create a document from a array of objects, each object representing a row and save it as buffer?
Upvotes: 8
Views: 8069
Reputation: 136
You can use the write
function and pass the WritingOptions
object to set the type of your workbook data.
Example:
const workbook = XLSX.utils.book_new()
const filename = 'mySheet'
const dataSheet = XLSX.utils.json_to_sheet(myJSONData)
XLSX.utils.book_append_sheet(workbook, dataSheet, filename.replace('/', ''))
and return for your controller, send it to the network, etc...
return XLSX.write(workbook, { type: 'buffer', bookType: 'csv' })
Upvotes: 12