# ExcelJS — Read, Write, and Stream Excel Spreadsheets in Node.js > A full-featured library for creating, reading, and manipulating XLSX and CSV files in Node.js with streaming support for large datasets. ## Install Save as a script file and run: # ExcelJS — Read, Write, and Stream Excel Spreadsheets in Node.js ## Quick Use ```bash npm install exceljs ``` ```js const ExcelJS = require('exceljs'); const workbook = new ExcelJS.Workbook(); const sheet = workbook.addWorksheet('Report'); sheet.addRow(['Name', 'Score']); sheet.addRow(['Alice', 95]); await workbook.xlsx.writeFile('report.xlsx'); ``` ## Introduction ExcelJS provides a complete API for generating and parsing Excel files in Node.js without requiring Microsoft Office. It supports rich formatting, formulas, images, charts metadata, and streaming — making it suitable for server-side report generation and ETL pipelines that handle millions of rows. ## What ExcelJS Does - Creates XLSX workbooks with multiple sheets, cell styles, merged cells, and conditional formatting - Reads existing XLSX files preserving formulas, data validations, and defined names - Streams rows to disk or HTTP responses for memory-efficient export of large datasets - Supports CSV reading and writing with configurable delimiters and encoding - Handles rich cell types including dates, hyperlinks, rich text, and images ## Architecture Overview ExcelJS models workbooks as in-memory object graphs of worksheets, rows, and cells. The XLSX serializer uses a streaming XML writer (SAX-style) that flushes sheet data in chunks, preventing memory exhaustion on large exports. For reading, it provides both a full-parse mode (entire workbook in memory) and a streaming reader that emits row events, suitable for processing files that exceed available RAM. ## Self-Hosting & Configuration - Install from npm — pure JavaScript, no native bindings required - Use `workbook.xlsx.writeFile(path)` for disk output or `workbook.xlsx.write(stream)` for HTTP responses - Enable streaming writes via `new ExcelJS.stream.xlsx.WorkbookWriter({ stream })` for constant-memory exports - Configure default column widths, row heights, and page setup (orientation, margins) per worksheet - Set number formats, fonts, borders, and fills at the cell or column level ## Key Features - Streaming writer keeps memory flat regardless of row count — tested with 1M+ rows - Full style support: fonts, fills, borders, alignment, number formats, and conditional formatting - Data validation rules (dropdowns, numeric ranges) embedded directly in cells - Auto-filter and freeze-pane support for user-friendly spreadsheets - Over 15,000 GitHub stars and 4 million weekly npm downloads ## Comparison with Similar Tools - **SheetJS (xlsx)** — broader format support (XLS, ODS); ExcelJS offers richer styling and streaming writes - **openpyxl (Python)** — Python equivalent; ExcelJS is the Node.js counterpart with similar capabilities - **Apache POI (Java)** — enterprise-grade but JVM-only; ExcelJS runs anywhere Node.js does - **csv-parser** — CSV-only streaming reader; ExcelJS handles both XLSX and CSV in one library - **json2csv** — converts JSON to CSV; ExcelJS produces formatted Excel files with charts and styles ## FAQ **Q: Can ExcelJS handle files with 100K+ rows?** A: Yes. Use the streaming WorkbookWriter for writing and the streaming reader for parsing to maintain constant memory usage. **Q: Does it support Excel formulas?** A: Yes. You can set formula strings on cells. Results are calculated by Excel when the file is opened, not by ExcelJS itself. **Q: Can I add images to spreadsheets?** A: Yes. Use `worksheet.addImage()` with a buffer or file path. Supported formats include PNG, JPEG, and GIF. **Q: Is it compatible with LibreOffice and Google Sheets?** A: The generated XLSX files conform to the Open XML standard and open correctly in LibreOffice Calc and Google Sheets. ## Sources - https://github.com/exceljs/exceljs - https://github.com/exceljs/exceljs/blob/master/README.md --- Source: https://tokrepo.com/en/workflows/asset-cc9ce2fb Author: Script Depot