SheetJS Spreadsheet data parser and writer
The xlsx package (SheetJS) is the de facto standard library for working with spreadsheet files in JavaScript. It handles parsing and generating Excel files across multiple formats including XLSX, XLS, XLSB, CSV, and ODS, making it possible to extract data from complex spreadsheets or generate new ones programmatically without relying on Excel itself.
With over 5 million weekly downloads, xlsx has become the foundational library that many other Excel-handling packages build upon. It runs in Node.js, browsers, and Electron environments, providing a consistent API regardless of platform. The library can handle both simple data extraction tasks and complex workbook manipulation, including multi-sheet workbooks, formula preservation, and various cell types.
Developers reach for xlsx when building data import/export features, automated reporting systems, or any application that needs to interface with Excel files. Its broad format support and battle-tested codebase make it reliable for production applications handling financial data, user uploads, bulk data operations, and enterprise integrations where Excel remains a common interchange format.
The library follows a workbook-worksheet-cell hierarchy that mirrors Excel's structure. You can read existing files into JavaScript objects, manipulate the data using standard array and object methods, then write the results back to various formats. This approach gives you full control over spreadsheet data while abstracting away the complexity of binary Excel formats and XML parsing.
import XLSX from 'xlsx';
import fs from 'fs';
// Reading an Excel file and converting to JSON
const workbook = XLSX.readFile('sales-data.xlsx');
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet);
console.log(jsonData);
// [{ Name: 'Product A', Sales: 1200, Region: 'North' }, ...]
// Creating a new workbook from JSON data
const employees = [
{ ID: 1, Name: 'Alice Johnson', Department: 'Engineering', Salary: 95000 },
{ ID: 2, Name: 'Bob Smith', Department: 'Marketing', Salary: 72000 },
{ ID: 3, Name: 'Carol White', Department: 'Engineering', Salary: 88000 }
];
const newWorkbook = XLSX.utils.book_new();
const newWorksheet = XLSX.utils.json_to_sheet(employees);
XLSX.utils.book_append_sheet(newWorkbook, newWorksheet, 'Employees');
// Write to file (Node.js)
XLSX.writeFile(newWorkbook, 'employees-export.xlsx');
// Or generate buffer for HTTP response
const buffer = XLSX.write(newWorkbook, { type: 'buffer', bookType: 'xlsx' });
// res.send(buffer);
// Working with specific cell ranges
const range = XLSX.utils.decode_range(worksheet['!ref']);
for (let row = range.s.r; row <= range.e.r; row++) {
const cellAddress = XLSX.utils.encode_cell({ r: row, c: 0 });
const cell = worksheet[cellAddress];
if (cell && cell.v) {
console.log(`Row ${row}: ${cell.v}`);
}
}Data Import from User Uploads: Accept Excel files from users in web applications, parse them into JSON, validate the data, and insert it into your database. Common in admin panels, CRM systems, and inventory management tools where bulk data entry via spreadsheet is more efficient than manual forms.
Automated Report Generation: Generate Excel reports from database queries or API data, complete with multiple sheets, headers, and formatted cells. Used in analytics dashboards, financial reporting systems, and business intelligence tools where stakeholders expect downloadable Excel files.
ETL Pipeline Integration: Transform data between Excel and other formats (CSV, JSON, databases) as part of data processing workflows. Frequently used in data warehouses, migration scripts, and integration platforms that need to consume or produce Excel files from legacy systems.
Spreadsheet Data Analysis: Read large Excel files, perform calculations or transformations on the data, and output results. Applied in scientific computing, financial modeling, and batch processing scenarios where Excel serves as the input data source.
Multi-format Export Systems: Provide users with download options in multiple formats (XLSX, CSV, ODS) from the same data source. Common in SaaS applications, reporting tools, and data visualization platforms that need format flexibility for different user preferences.
npm install xlsxpnpm add xlsxbun add xlsx