xlsx2csv for browser and nodejs with performance considered
npm i @ailnaf/xlsx2csv
import xlsx2csv from '@ailnaf/xlsx2csv'
<script src="https://unpkg.com/@ailnaf/xlsx2csv/xlsx2csv.min.js"></script>
const { default: xlsx2csv } = await import('@ailnaf/xlsx2csv')
const filename = 'data.xlsx'
xlsx2csv(filename, console.log)
const buffer = await fetch('data.xlsx').then(res => res.blob())
xlsx2csv(buffer, console.log, { sheet: { max: 100 } })
// [ 'hello', 'world' ]
// [ 'bar', 'foo' ]
const rows = await xlsx2csv(buffer, null, { sheet: { max: 100, collect: true } })
console.log(rows)
// [ [ 'hello', 'world' ], [ 'bar', 'foo' ] ]
const rows = await xlsx2csv(buffer, null, { sheet: { max: 100, collect: true, json: true } })
console.log(rows)
// [ { hello: 'bar', world: 'foo' } ]
for small files browser and nodejs
import csv2xlsx from '@ailnaf/xlsx2csv/csv2xlsx'
const source = [
['number1', 'number2', 'hello', 'number3', null, 'date', 'list'],
[12.7, 12.8, 'world', '100', null, new Date(), [1,2,3]],
]
csv2xlsx(source)
.then(buf => {
console.log(buf)
})
.catch(console.log)
# all data
node test.js data.xlsx
# 1 row
node test.js data.xlsx 1
MIT