sheetjs
📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs
Top Related Projects
Excel Workbook Manager
JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡
A pure PHP library for reading and writing spreadsheet files
A Python module for creating Excel XLSX files.
Quick Overview
SheetJS is a powerful and versatile JavaScript library for parsing, manipulating, and generating spreadsheet files. It supports various formats including Excel (.xlsx, .xls), CSV, and more, making it an essential tool for web applications that deal with spreadsheet data.
Pros
- Supports a wide range of spreadsheet formats
- Works in both browser and Node.js environments
- Highly performant, capable of handling large datasets
- Extensive documentation and community support
Cons
- Large file size, which may impact load times for web applications
- Some advanced features require a commercial license
- Learning curve can be steep for complex operations
- Limited styling options for generated spreadsheets
Code Examples
- Reading an Excel file:
import * as XLSX from 'xlsx';
const workbook = XLSX.readFile('example.xlsx');
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const data = XLSX.utils.sheet_to_json(worksheet);
console.log(data);
- Creating a new workbook and writing to a file:
import * as XLSX from 'xlsx';
const data = [
{ name: 'John', age: 30 },
{ name: 'Jane', age: 28 }
];
const worksheet = XLSX.utils.json_to_sheet(data);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
XLSX.writeFile(workbook, 'output.xlsx');
- Converting CSV to XLSX:
import * as XLSX from 'xlsx';
const csv = `Name,Age\nJohn,30\nJane,28`;
const workbook = XLSX.read(csv, { type: 'string' });
XLSX.writeFile(workbook, 'converted.xlsx');
Getting Started
To use SheetJS in your project, first install it via npm:
npm install xlsx
Then, import and use it in your JavaScript code:
import * as XLSX from 'xlsx';
// Read a file
const workbook = XLSX.readFile('example.xlsx');
// Access the first sheet
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
// Convert sheet data to JSON
const data = XLSX.utils.sheet_to_json(worksheet);
console.log(data);
This basic example demonstrates how to read an Excel file and convert its contents to a JavaScript object.
Competitor Comparisons
Excel Workbook Manager
Pros of ExcelJS
- Better support for advanced Excel features like cell styles, formulas, and charts
- More comprehensive documentation and examples
- Active development with frequent updates and bug fixes
Cons of ExcelJS
- Slower performance for large datasets compared to SheetJS
- Larger file size and more dependencies
- Steeper learning curve for basic operations
Code Comparison
ExcelJS:
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Sheet1');
worksheet.getCell('A1').value = 'Hello, World!';
worksheet.getCell('A1').font = { bold: true, color: { argb: 'FF0000' } };
await workbook.xlsx.writeFile('example.xlsx');
SheetJS:
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.aoa_to_sheet([['Hello, World!']]);
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
XLSX.writeFile(workbook, 'example.xlsx');
ExcelJS offers more granular control over cell formatting and styles, while SheetJS provides a simpler API for basic operations. ExcelJS is better suited for complex Excel manipulations, whereas SheetJS excels in performance and simplicity for large datasets and basic spreadsheet tasks.
JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡
Pros of Handsontable
- Rich, interactive spreadsheet-like interface with advanced features
- Extensive customization options for appearance and behavior
- Built-in support for data validation, sorting, and filtering
Cons of Handsontable
- Larger file size and potentially higher performance overhead
- Steeper learning curve due to more complex API
- Limited support for advanced Excel features like formulas
Code Comparison
Handsontable:
const hot = new Handsontable(container, {
data: dataset,
rowHeaders: true,
colHeaders: true,
filters: true,
dropdownMenu: true
});
SheetJS:
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.json_to_sheet(dataset);
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
XLSX.writeFile(workbook, "output.xlsx");
Handsontable provides a more interactive, spreadsheet-like experience with built-in UI components, while SheetJS focuses on efficient data processing and file manipulation without a visual interface. Handsontable is better suited for creating editable data grids in web applications, whereas SheetJS excels at reading, writing, and manipulating Excel files programmatically.
A pure PHP library for reading and writing spreadsheet files
Pros of PhpSpreadsheet
- Native PHP implementation, ideal for PHP-based projects
- Extensive support for various spreadsheet formats (XLSX, XLS, ODS, CSV, etc.)
- Robust formula calculation engine
Cons of PhpSpreadsheet
- Limited to PHP environments, less versatile than SheetJS
- Generally slower performance compared to SheetJS
- Steeper learning curve for beginners
Code Comparison
PhpSpreadsheet:
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World!');
$writer = new Xlsx($spreadsheet);
$writer->save('hello_world.xlsx');
SheetJS:
const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.aoa_to_sheet([['Hello World!']]);
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
XLSX.writeFile(workbook, 'hello_world.xlsx');
Both libraries offer powerful spreadsheet manipulation capabilities, but they cater to different ecosystems. PhpSpreadsheet is tailored for PHP developers and provides deep integration with PHP projects. It excels in handling complex spreadsheet operations and supports a wide range of formats. However, it's limited to PHP environments and may have performance issues with large datasets.
SheetJS, on the other hand, is more versatile, supporting multiple programming languages and environments. It generally offers better performance and is easier for beginners to pick up. However, it may lack some of the advanced features and format support that PhpSpreadsheet provides.
Choose based on your project requirements, development environment, and performance needs.
A Python module for creating Excel XLSX files.
Pros of XlsxWriter
- Specialized for creating Excel XLSX files, offering more Excel-specific features
- Supports advanced Excel functionalities like charts, tables, and conditional formatting
- Lightweight and has no external dependencies
Cons of XlsxWriter
- Limited to writing XLSX files; cannot read or modify existing files
- Python-only library, not available for other programming languages
- Slower performance for very large datasets compared to SheetJS
Code Comparison
XlsxWriter:
import xlsxwriter
workbook = xlsxwriter.Workbook('example.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello')
workbook.close()
SheetJS:
const XLSX = require('xlsx');
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet([['Hello']]);
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, 'example.xlsx');
Both libraries provide straightforward ways to create Excel files, but XlsxWriter's API is more Excel-centric, while SheetJS offers a more generic approach that works with various spreadsheet formats. SheetJS is more versatile in terms of supported languages and file operations, while XlsxWriter excels in creating feature-rich Excel files specifically.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
[!IMPORTANT]
Thank you Clippy!
But our Sheet is in another Workbook!
The new source repository URL is https://git.sheetjs.com/sheetjs/sheetjs. SheetJS CE remains truly open source under the Apache 2.0 License.
Issues should be raised at https://git.sheetjs.com/sheetjs/sheetjs/issues. Users can register directly or sign in with a valid GitHub account. Issues can also be raised at https://sheetjs.com/chat.
Documentation is available at https://docs.sheetjs.com.
Scripts and NodeJS modules are available at https://cdn.sheetjs.com.
The
master
branch branch of theSheetJS/sheetjs
repository on GitHub includes all commits through515d1c6f2e1d3ca422ee9198b177cfd926434936
.
The SheetJS Community Edition offers battle-tested open-source solutions for extracting useful data from almost any complex spreadsheet and generating new spreadsheets that will work with legacy and modern software alike.
SheetJS Pro offers solutions beyond data processing: Edit complex templates with ease; let out your inner Picasso with styling; make custom sheets with images/graphs/PivotTables; evaluate formula expressions and port calculations to web apps; automate common spreadsheet tasks, and much more!
[!NOTE]
ð¼ We're Hiring!
SheetJS is looking for US-based software developers to expand this project and related software libraries and tools. https://sheetjs.com/careers more info.
Resources
License
Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 License are reserved by the Original Author.
Top Related Projects
Excel Workbook Manager
JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡
A pure PHP library for reading and writing spreadsheet files
A Python module for creating Excel XLSX files.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot