(one day) a full-featured XLS parser and writer. For now, primitive parser
npm install xlsjs
|78||downloads in the last day|
|254||downloads in the last week|
|629||downloads in the last month|
|Version||0.6.9-c last updated 14 days ago|
|Keywords||xls, office, excel, spreadsheet|
|Dependencies||cfb, ssf, codepage, commander|
|Dependents (7)||animas-diasend-data, crackajax, gulp-xls2json, j, tidepool-animas-diasend-data, tool4ssh, xls-to-json|
|Starred by||mathjs, mytharcher, niggler, sheetjs|
Currently a parser for XLS (BIFF8) and XML (2003/2004) files. Cleanroom implementation from the Microsoft Open Specifications.
npm install xlsjs
In the browser:
Simple usage (gets the value of cell A1 of sheet Sheet1):
var XLS = require('xlsjs'); var xls = XLS.readFile('test.xls'); var Sheet1A1 = xls.Sheets['Sheet1']['A1'].v;
The node version installs a binary
xls2csv which can read XLS files and output the contents in various formats. The source is available at
xls2csv.njs in the bin directory.
See http://oss.sheetjs.com/js-xls/ for a browser example.
Some helper functions in
XLS.utils generate different views of the sheets:
XLS.utils.sheet_to_row_object_arrayinterprets sheets as tables with a header column and generates an array of objects
XLS.utils.get_formulaegenerates a list of formulae
For more details:
bin/xls2csv.njsis a tool for node
index.htmlis the live demo
bits/80_xls.jscontains the logic for generating CSV and JSON from sheets
Cell Object Description
.SheetNames is an ordered list of the sheets in the workbook
.Sheets[sheetname] returns a data structure representing the sheet. Each key
that does not start with
! corresponds to a cell (using
.Sheets[sheetname][address] returns the specified cell:
.v: the raw value of the cell
.w: the formatted text of the cell (if applicable)
.t: the type of the cell (constrained to the enumeration
ST_CellTypeas documented in page 4215 of ISO/IEC 29500-1:2012(E) )
.f: the formula of the cell (if applicable)
.z: the number format string associated with the cell (if requested)
.v holds the raw date code from the sheet and
.w holds the text
readFile functions accept an options argument:
|cellFormula||true||Save formulae to the .f field **|
|cellNF||false||Save number format string to the .z field|
|sheetRows||0||If >0, read the first
|bookFiles||false||If true, add raw files to book object **|
|bookProps||false||If true, only parse enough to get book metadata **|
|bookSheets||false||If true, only parse enough to get the sheet names|
- Even if
cellNFis false, formatted text (.w) will be generated
- In some cases, sheets may be parsed even if
bookPropscombine to give both sets of information
sheetRows-1rows will be generated when looking at the JSON object output (since the header row is counted as a row when parsing the data)
CFB refers to the Microsoft Compound File Binary Format, a container format for XLS as well as DOC and other pre-OOXML data formats.
The mechanism is split into a CFB parser (which scans through the file and produces concrete data chunks) and a Workbook parser (which does excel-specific parsing). XML files are not processed by the CFB parser.
Test files are housed in another repo.
make init will refresh the
test_files submodule and get the files.
Tests utilize the mocha testing framework. Travis-CI and Sauce Labs links:
- https://travis-ci.org/SheetJS/js-xls for XLS module in node
- https://travis-ci.org/SheetJS/SheetJS.github.io for XLS* modules
- https://saucelabs.com/u/sheetjs for XLS* modules using Sauce Labs
Due to the precarious nature of the Open Specifications Promise, it is very important to ensure code is cleanroom. Consult CONTRIBUTING.md
XLSX/XLSM/XLSB is available in js-xlsx.
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.
It is the opinion of the Original Author that this code conforms to the terms of the Microsoft Open Specifications Promise, falling under the same terms as OpenOffice (which is governed by the Apache License v2). Given the vagaries of the promise, the Original Author makes no legal claim that in fact end users are protected from future actions. It is highly recommended that, for commercial uses, you consult a lawyer before proceeding.
- [MS-CFB]: Compound File Binary File Format
- [MS-XLS]: Excel Binary File Format (.xls) Structure Specification
- [MS-XLSB]: Excel (.xlsb) Binary File Format
- [MS-XLSX]: Excel (.xlsx) Extensions to the Office Open XML SpreadsheetML File Format
- [MS-ODATA]: Open Data Protocol (OData)
- [MS-OFFCRYPTO]: Office Document Cryptography Structure
- [MS-OLEDS]: Object Linking and Embedding (OLE) Data Structures
- [MS-OLEPS]: Object Linking and Embedding (OLE) Property Set Data Structures
- [MS-OSHARED]: Office Common Data Types and Objects Structures
- [MS-OVBA]: Office VBA File Format Structure
- [MS-OE376]: Office Implementation Information for ECMA-376 Standards Support
- [XLS]: Microsoft Office Excel 97-2007 Binary File Format Specification
Certain features are shared with the Office Open XML File Formats, covered in:
ISO/IEC 29500:2012(E) "Information technology — Document description and processing languages — Office Open XML File Formats"