Skip to content

fanlia/xlsx2csv

Repository files navigation

xlsx2csv

xlsx2csv for browser and nodejs with performance considered

demo

Install

npm i @ailnaf/xlsx2csv

Usage

esm

import xlsx2csv from '@ailnaf/xlsx2csv'

cdn

<script src="https://unpkg.com/@ailnaf/xlsx2csv/xlsx2csv.min.js"></script>

cjs

const { default: xlsx2csv } = await import('@ailnaf/xlsx2csv')

nodejs

const filename = 'data.xlsx'

xlsx2csv(filename, console.log)

browser

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' } ]

export xlsx

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)

Test

# all data
node test.js data.xlsx

# 1 row
node test.js data.xlsx 1

License

MIT

About

xlsx2csv for browser and nodejs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published