xxx_coder_noscope
xxx_coder_noscope

Reputation: 85

SheetJS How to create sheet from json and save it as buffer

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

Answers (1)

Aislan de Sousa Maia
Aislan de Sousa Maia

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

Related Questions