sheet-to-array-browser
v2.3.0
Published
converts sheet data to javascript array
Maintainers
Readme
sheet-to-array-browser
Convert Excel/Sheet files (.xlsx, .xls) into JavaScript arrays with ease.
Works in both browsers (via <input type="file"> or drag-drop) and Node.js.
✨ Features
- ✅ Parse
.xlsxand.xlsfiles into JSON/arrays - ✅ Works in browsers and Node.js
- ✅ Supports selecting a specific worksheet (by index or name)
- ✅ Built on SheetJS/xlsx
- ✅ Lightweight, tree-shakeable, TypeScript-ready
📦 Installation
npm i sheet-to-array-browser🚀 Usage
Browser (with file input)
import { parseWorkbook } from "sheet-to-array-browser";
document.getElementById("fileInput").addEventListener("change", async (e) => {
const file = e.target.files[0];
const rows = await parseWorkbook(file, { sheet: 0 });
console.log(rows);
});Node.js (with Buffer/ArrayBuffer)
import { readFileSync } from "fs";
import { parseWorkbook } from "sheet-to-array-browser";
const buffer = readFileSync("./example.xlsx");
const rows = await parseWorkbook(buffer, { sheet: "Data" });
console.log(rows);📖 API
parseWorkbook(input, options?)
inputFile|Blob|ArrayBuffer|Buffer(Works with browser files, Node Buffers, or raw ArrayBuffers)
options(optional)sheet(number | string) → Which sheet to readindex (
0= first sheet)or sheet name (
"Data")default:
0
sheetToJson(XLSX.Sheet2JSONOpts) → Options passed toXLSX.utils.sheet_to_jsonReturns
Promise<Array<object>>→ An array of row objects.
🛠 Development
Clone the repo and run:
npm install
npm run build
npm test
npm run build → Build dist files
npm test → Run unit tests (Vitest)
npm run pack:check → Preview files that will publish