xlsx
- Version 0.18.5
- Published
- 7.5 MB
- 7 dependencies
- Apache-2.0 license
Install
npm i xlsx
yarn add xlsx
pnpm add xlsx
Overview
SheetJS Spreadsheet data parser and writer
Index
Variables
Functions
Interfaces
XLSX$Utils
- aoa_to_sheet()
- book_append_sheet()
- book_new()
- book_set_sheet_visibility()
- cell_add_comment()
- cell_set_hyperlink()
- cell_set_internal_link()
- cell_set_number_format()
- consts
- decode_cell()
- decode_col()
- decode_range()
- decode_row()
- encode_cell()
- encode_col()
- encode_range()
- encode_row()
- format_cell()
- json_to_sheet()
- sheet_add_aoa()
- sheet_add_dom()
- sheet_add_json()
- sheet_set_array_formula()
- sheet_to_csv()
- sheet_to_dif()
- sheet_to_eth()
- sheet_to_formulae()
- sheet_to_html()
- sheet_to_json()
- sheet_to_slk()
- sheet_to_txt()
- table_to_book()
- table_to_sheet()
Type Aliases
Variables
Functions
function read
read: (data: any, opts?: ParsingOptions) => WorkBook;
Attempts to parse data
function readFile
readFile: (filename: string, opts?: ParsingOptions) => WorkBook;
NODE ONLY! Attempts to read filename and parse
function set_cptable
set_cptable: (cptable: any) => void;
ESM ONLY! Set internal codepage tables
function set_fs
set_fs: (fs: any) => void;
ESM ONLY! Set internal
fs
instance
function write
write: (data: WorkBook, opts: WritingOptions) => any;
Attempts to write the workbook data
function writeFile
writeFile: (data: WorkBook, filename: string, opts?: WritingOptions) => any;
Attempts to write or download workbook data to file
function writeFileAsync
writeFileAsync: ( filename: string, data: WorkBook, opts: WritingOptions | CBFunc, cb?: CBFunc) => any;
function writeFileXLSX
writeFileXLSX: (data: WorkBook, filename: string, opts?: WritingOptions) => any;
Attempts to write or download workbook data to XLSX file
function writeXLSX
writeXLSX: (data: WorkBook, opts: WritingOptions) => any;
Attempts to write the workbook data as XLSX
Interfaces
interface AOA2SheetOpts
interface AOA2SheetOpts extends CommonOptions, DateNFOption {}
property sheetStubs
sheetStubs?: boolean;
Create cell objects for stub cells false
interface AutoFilterInfo
interface AutoFilterInfo {}
AutoFilter properties
property ref
ref: string;
Range of the AutoFilter table
interface CellAddress
interface CellAddress {}
Simple Cell Address
interface CellObject
interface CellObject {}
Worksheet Cell Object
property c
c?: Comments;
Comments associated with the cell
property f
f?: string;
Cell formula (if applicable)
property F
F?: string;
Range of enclosing array if formula is array formula (if applicable)
property h
h?: string;
HTML rendering of the rich text (if applicable)
property l
l?: Hyperlink;
Cell hyperlink object (.Target holds link, .tooltip is tooltip)
property r
r?: any;
Rich text encoding (if applicable)
property s
s?: any;
The style/theme of the cell (if applicable)
property t
t: ExcelDataType;
The Excel Data Type of the cell. b Boolean, n Number, e Error, s String, d Date, z Empty
property v
v?: string | number | boolean | Date;
The raw value of the cell. Can be omitted if a formula is specified
property w
w?: string;
Formatted text (if applicable)
property z
z?: NumberFormat;
Number format string associated with the cell (if requested)
interface ColInfo
interface ColInfo {}
Column Properties Object
property DBF
DBF?: DBFField;
DBF Field Header
property hidden
hidden?: boolean;
if true, the column is hidden
property level
level?: number;
outline / group level
property MDW
MDW?: number;
Excel's "Max Digit Width" unit, always integral
property wch
wch?: number;
width in "characters"
property width
width?: number;
width in Excel's "Max Digit Width", width*256 is integral
property wpx
wpx?: number;
width in screen pixels
interface Comment
interface Comment {}
Comment element
interface Comments
interface Comments extends Array<Comment> {}
Cell comments
property hidden
hidden?: boolean;
Hide comment by default
interface CommonOptions
interface CommonOptions {}
property bookVBA
bookVBA?: boolean;
When reading a file with VBA macros, expose CFB blob to
vbaraw
field When writing BIFF8/XLSB/XLSM, reseatvbaraw
and export to file false
property cellDates
cellDates?: boolean;
When reading a file, store dates as type d (default is n) When writing XLSX/XLSM file, use native date (default uses date codes) false
property cellStyles
cellStyles?: boolean;
When reading a file, save style/theme info to the .s field When writing a file, export style/theme info false
property password
password?: string;
If defined and file is encrypted, use password ''
property sheetStubs
sheetStubs?: boolean;
Create cell objects for stub cells false
property WTF
WTF?: boolean;
If true, throw errors when features are not understood false
interface DateNFOption
interface DateNFOption {}
property dateNF
dateNF?: NumberFormat;
Use specified date format
interface DBFField
interface DBFField {}
DBF Field Header
interface DefinedName
interface DefinedName {}
Defined Name Object
interface FullProperties
interface FullProperties extends Properties {}
Other supported properties
property Application
Application?: string;
property AppVersion
AppVersion?: string;
property ContentStatus
ContentStatus?: string;
property DocSecurity
DocSecurity?: string;
property HyperlinksChanged
HyperlinksChanged?: boolean;
property Identifier
Identifier?: string;
property Language
Language?: string;
property LastPrinted
LastPrinted?: string;
property LinksUpToDate
LinksUpToDate?: boolean;
property ModifiedDate
ModifiedDate?: Date;
property Revision
Revision?: string | number;
property ScaleCrop
ScaleCrop?: boolean;
property SharedDoc
SharedDoc?: boolean;
property SheetNames
SheetNames?: string[];
property Version
Version?: string;
property Worksheets
Worksheets?: number;
interface Hyperlink
interface Hyperlink {}
Link object
interface JSON2SheetOpts
interface JSON2SheetOpts extends CommonOptions, DateNFOption {}
property header
header?: string[];
Use specified column order
property skipHeader
skipHeader?: boolean;
Skip header row in generated sheet
interface MarginInfo
interface MarginInfo {}
Page Margins -- see Excel Page Setup .. Margins diagram for explanation
property bottom
bottom?: number;
Bottom side margin (inches)
property footer
footer?: number;
Footer bottom height (inches)
property header
header?: number;
Header top margin (inches)
property left
left?: number;
Left side margin (inches)
property right
right?: number;
Right side margin (inches)
property top
top?: number;
Top side margin (inches)
interface OriginOption
interface OriginOption {}
property origin
origin?: number | string | CellAddress;
Top-Left cell for operation (CellAddress or A1 string or row)
interface ParsingOptions
interface ParsingOptions extends CommonOptions {}
Options for read and readFile
property bookDeps
bookDeps?: boolean;
If true, parse calculation chains false
property bookFiles
bookFiles?: boolean;
If true, add raw files to book object false
property bookProps
bookProps?: boolean;
If true, only parse enough to get book metadata false
property bookSheets
bookSheets?: boolean;
If true, only parse enough to get the sheet names false
property cellFormula
cellFormula?: boolean;
Save formulae to the .f field true
property cellHTML
cellHTML?: boolean;
Parse rich text and save HTML to the .h field true
property cellNF
cellNF?: boolean;
Save number format string to the .z field false
property cellText
cellText?: boolean;
Generate formatted text to the .w field true
property codepage
codepage?: number;
Default codepage
property dateNF
dateNF?: string;
Override default date format (code 14)
property dense
dense?: boolean;
property FS
FS?: string;
Field Separator ("Delimiter" override)
property PRN
PRN?: boolean;
property raw
raw?: boolean;
If true, plaintext parsing will not parse values
property sheetRows
sheetRows?: number;
If >0, read the first sheetRows rows 0
property sheets
sheets?: number | string | Array<number | string>;
If specified, only parse the specified sheets or sheet names
property type
type?: 'base64' | 'binary' | 'buffer' | 'file' | 'array' | 'string';
Input data encoding
property xlfn
xlfn?: boolean;
If true, preserve _xlfn. prefixes in formula function names
interface Properties
interface Properties {}
Basic File Properties
property Author
Author?: string;
Summary tab "Author"
property Category
Category?: string;
Summary tab "Category"
property Comments
Comments?: string;
Summary tab "Comments"
property Company
Company?: string;
Summary tab "Company"
property CreatedDate
CreatedDate?: Date;
Statistics tab "Created"
property Keywords
Keywords?: string;
Summary tab "Keywords"
property LastAuthor
LastAuthor?: string;
Statistics tab "Last saved by"
property Manager
Manager?: string;
Summary tab "Manager"
property Subject
Subject?: string;
Summary tab "Subject"
property Title
Title?: string;
Summary tab "Title"
interface ProtectInfo
interface ProtectInfo {}
Write sheet protection properties.
property autoFilter
autoFilter?: boolean;
Filter @default: false
property deleteColumns
deleteColumns?: boolean;
Delete columns @default: false
property deleteRows
deleteRows?: boolean;
Delete rows @default: false
property formatCells
formatCells?: boolean;
Format cells @default: false
property formatColumns
formatColumns?: boolean;
Format columns @default: false
property formatRows
formatRows?: boolean;
Format rows @default: false
property insertColumns
insertColumns?: boolean;
Insert columns @default: false
property insertHyperlinks
insertHyperlinks?: boolean;
Insert hyperlinks @default: false
property insertRows
insertRows?: boolean;
Insert rows @default: false
property objects
objects?: boolean;
Edit objects @default: true
property password
password?: string;
The password for formats that support password-protected sheets (XLSX/XLSB/XLS). The writer uses the XOR obfuscation method.
property pivotTables
pivotTables?: boolean;
Use PivotTable reports @default: false
property scenarios
scenarios?: boolean;
Edit scenarios @default: true
property selectLockedCells
selectLockedCells?: boolean;
Select locked cells @default: true
property selectUnlockedCells
selectUnlockedCells?: boolean;
Select unlocked cells @default: true
property sort
sort?: boolean;
Sort @default: false
interface Range
interface Range {}
Range object (representing ranges like "A1:B2")
interface RowInfo
interface RowInfo {}
Row Properties Object
interface Sheet
interface Sheet {}
General object representing a Sheet (worksheet or chartsheet)
property '!margins'
'!margins'?: MarginInfo;
Page Margins
property '!ref'
'!ref'?: string;
Sheet Range
property '!type'
'!type'?: SheetType;
Sheet type
index signature
[cell: string]: CellObject | SheetKeys | any;
Indexing with a cell address string maps to a cell object Special keys start with '!'
interface Sheet2CSVOpts
interface Sheet2CSVOpts extends DateNFOption {}
property blankrows
blankrows?: boolean;
Include blank lines in the CSV output
property forceQuotes
forceQuotes?: boolean;
Force quotes around fields
property FS
FS?: string;
Field Separator ("delimiter")
property rawNumbers
rawNumbers?: boolean;
if true, return raw numbers; if false, return formatted numbers
property RS
RS?: string;
Record Separator ("row separator")
property skipHidden
skipHidden?: boolean;
Skip hidden rows and columns in the CSV output
property strip
strip?: boolean;
Remove trailing field separators in each record
interface Sheet2HTMLOpts
interface Sheet2HTMLOpts {}
interface Sheet2JSONOpts
interface Sheet2JSONOpts extends DateNFOption {}
property blankrows
blankrows?: boolean;
Include or omit blank lines in the output
property defval
defval?: any;
Default value for null/undefined values
property header
header?: 'A' | number | string[];
Output format
property range
range?: any;
Override worksheet range
property raw
raw?: boolean;
if true, return raw data; if false, return formatted text
property rawNumbers
rawNumbers?: boolean;
if true, return raw numbers; if false, return formatted numbers
property skipHidden
skipHidden?: boolean;
if true, skip hidden rows and columns
interface SheetAOAOpts
interface SheetAOAOpts extends AOA2SheetOpts, OriginOption {}
interface SheetJSONOpts
interface SheetJSONOpts extends JSON2SheetOpts, OriginOption {}
interface SheetOption
interface SheetOption {}
property sheet
sheet?: string;
Name of Worksheet (for single-sheet formats) ''
interface SheetProps
interface SheetProps {}
interface StreamUtils
interface StreamUtils {}
NODE ONLY! these return Readable Streams
method set_readable
set_readable: (Readable: any) => void;
Set
Readable
(internal)
method to_csv
to_csv: (sheet: WorkSheet, opts?: Sheet2CSVOpts) => any;
CSV output stream, generate one line at a time
method to_html
to_html: (sheet: WorkSheet, opts?: Sheet2HTMLOpts) => any;
HTML output stream, generate one line at a time
method to_json
to_json: (sheet: WorkSheet, opts?: Sheet2JSONOpts) => any;
JSON object stream, generate one row at a time
interface StrictWS
interface StrictWS {}
Worksheet Object with CellObject type
The normal Worksheet type uses indexer of type
any
-- this enforces CellObject
index signature
[addr: string]: CellObject;
interface Table2SheetOpts
interface Table2SheetOpts extends CommonOptions, DateNFOption, OriginOption, SheetOption {}
interface WBProps
interface WBProps {}
Workbook-Level Attributes
interface WorkBook
interface WorkBook {}
Workbook Object
property Custprops
Custprops?: object;
Custom workbook Properties
property Props
Props?: FullProperties;
Standard workbook Properties
property SheetNames
SheetNames: string[];
Ordered list of the sheet names in the workbook
property Sheets
Sheets: { [sheet: string]: WorkSheet };
A dictionary of the worksheets in the workbook. Use SheetNames to reference these.
property vbaraw
vbaraw?: any;
property Workbook
Workbook?: WBProps;
interface WorkbookProperties
interface WorkbookProperties {}
Other Workbook Properties
property CodeName
CodeName?: string;
Name of Document Module in associated VBA Project
property date1904
date1904?: boolean;
Worksheet Epoch (1904 if true, 1900 if false)
property filterPrivacy
filterPrivacy?: boolean;
Warn or strip personally identifying info on save
interface WorkSheet
interface WorkSheet extends Sheet {}
Worksheet Object
property '!autofilter'
'!autofilter'?: AutoFilterInfo;
AutoFilter info
property '!cols'
'!cols'?: ColInfo[];
Column Info
property '!merges'
'!merges'?: Range[];
Merge Ranges
property '!protect'
'!protect'?: ProtectInfo;
Worksheet Protection info
property '!rows'
'!rows'?: RowInfo[];
Row Info
index signature
[cell: string]: CellObject | WSKeys | any;
Indexing with a cell address string maps to a cell object Special keys start with '!'
interface WritingOptions
interface WritingOptions extends CommonOptions, SheetOption {}
Options for write and writeFile
property bookSST
bookSST?: boolean;
Generate Shared String Table false
property bookType
bookType?: BookType;
File format of generated workbook 'xlsx'
property compression
compression?: boolean;
Use ZIP compression for ZIP-based formats false
property ignoreEC
ignoreEC?: boolean;
Suppress "number stored as text" errors in generated files true
property numbers
numbers?: string;
Base64 encoding of NUMBERS base for exports
property Props
Props?: Properties;
Override workbook properties on save
property type
type?: 'base64' | 'binary' | 'buffer' | 'file' | 'array' | 'string';
Output data encoding
interface XLSX$Consts
interface XLSX$Consts {}
property SHEET_HIDDEN
SHEET_HIDDEN: 1;
Visibility: Hidden
property SHEET_VERYHIDDEN
SHEET_VERYHIDDEN: 2;
Visibility: Very Hidden
property SHEET_VISIBLE
SHEET_VISIBLE: 0;
Visibility: Visible
interface XLSX$Utils
interface XLSX$Utils {}
General utilities
property consts
consts: XLSX$Consts;
method aoa_to_sheet
aoa_to_sheet: { <T>(data: T[][], opts?: AOA2SheetOpts): WorkSheet; (data: any[][], opts?: AOA2SheetOpts): WorkSheet;};
Converts an array of arrays of JS data to a worksheet.
method book_append_sheet
book_append_sheet: ( workbook: WorkBook, worksheet: WorkSheet, name?: string, roll?: boolean) => void;
Append a worksheet to a workbook
method book_new
book_new: () => WorkBook;
Creates a new workbook
method book_set_sheet_visibility
book_set_sheet_visibility: ( workbook: WorkBook, sheet: number | string, visibility: number) => void;
Set sheet visibility (visible/hidden/very hidden)
method cell_add_comment
cell_add_comment: (cell: CellObject, text: string, author?: string) => void;
Add comment to a cell
method cell_set_hyperlink
cell_set_hyperlink: ( cell: CellObject, target: string, tooltip?: string) => CellObject;
Set hyperlink for a cell
method cell_set_internal_link
cell_set_internal_link: ( cell: CellObject, target: string, tooltip?: string) => CellObject;
Set internal link for a cell
method cell_set_number_format
cell_set_number_format: (cell: CellObject, fmt: string | number) => CellObject;
Set number format for a cell
method decode_cell
decode_cell: (address: string) => CellAddress;
Converts A1 cell address to 0-indexed form
method decode_col
decode_col: (col: string) => number;
Converts A1 column to 0-indexed form
method decode_range
decode_range: (range: string) => Range;
Converts A1 range to 0-indexed form
method decode_row
decode_row: (row: string) => number;
Converts A1 row to 0-indexed form
method encode_cell
encode_cell: (cell: CellAddress) => string;
Converts 0-indexed cell address to A1 form
method encode_col
encode_col: (col: number) => string;
Converts 0-indexed column to A1 form
method encode_range
encode_range: { (s: CellAddress, e: CellAddress): string; (r: Range): string };
Converts 0-indexed range to A1 form
method encode_row
encode_row: (row: number) => string;
Converts 0-indexed row to A1 form
method format_cell
format_cell: (cell: CellObject, v?: any, opts?: any) => string;
Format cell
method json_to_sheet
json_to_sheet: { <T>(data: T[], opts?: JSON2SheetOpts): WorkSheet; (data: any[], opts?: JSON2SheetOpts): WorkSheet;};
Converts an array of JS objects to a worksheet.
method sheet_add_aoa
sheet_add_aoa: { <T>(ws: WorkSheet, data: T[][], opts?: SheetAOAOpts): WorkSheet; (ws: WorkSheet, data: any[][], opts?: SheetAOAOpts): WorkSheet;};
Add an array of arrays of JS data to a worksheet
method sheet_add_dom
sheet_add_dom: (ws: WorkSheet, data: any, opts?: Table2SheetOpts) => WorkSheet;
method sheet_add_json
sheet_add_json: { (ws: WorkSheet, data: any[], opts?: SheetJSONOpts): WorkSheet; <T>(ws: WorkSheet, data: T[], opts?: SheetJSONOpts): WorkSheet;};
Add an array of JS objects to a worksheet
method sheet_set_array_formula
sheet_set_array_formula: ( ws: WorkSheet, range: Range | string, formula: string, dynamic?: boolean) => WorkSheet;
Assign an Array Formula to a range
method sheet_to_csv
sheet_to_csv: (worksheet: WorkSheet, options?: Sheet2CSVOpts) => string;
Generates delimiter-separated-values output
method sheet_to_dif
sheet_to_dif: (worksheet: WorkSheet, options?: Sheet2HTMLOpts) => string;
Generates DIF
method sheet_to_eth
sheet_to_eth: (worksheet: WorkSheet, options?: Sheet2HTMLOpts) => string;
Generates ETH
method sheet_to_formulae
sheet_to_formulae: (worksheet: WorkSheet) => string[];
Generates a list of the formulae (with value fallbacks)
method sheet_to_html
sheet_to_html: (worksheet: WorkSheet, options?: Sheet2HTMLOpts) => string;
Generates HTML
method sheet_to_json
sheet_to_json: { <T>(worksheet: WorkSheet, opts?: Sheet2JSONOpts): T[]; (worksheet: WorkSheet, opts?: Sheet2JSONOpts): any[][]; (worksheet: WorkSheet, opts?: Sheet2JSONOpts): any[];};
Converts a worksheet object to an array of JSON objects
method sheet_to_slk
sheet_to_slk: (worksheet: WorkSheet, options?: Sheet2HTMLOpts) => string;
Generates SYLK (Symbolic Link)
method sheet_to_txt
sheet_to_txt: (worksheet: WorkSheet, options?: Sheet2CSVOpts) => string;
Generates UTF16 Formatted Text
method table_to_book
table_to_book: (data: any, opts?: Table2SheetOpts) => WorkBook;
method table_to_sheet
table_to_sheet: (data: any, opts?: Table2SheetOpts) => WorkSheet;
BROWSER ONLY! Converts a TABLE DOM element to a worksheet.
Type Aliases
type BookType
type BookType = | 'xlsx' | 'xlsm' | 'xlsb' | 'xls' | 'xla' | 'biff8' | 'biff5' | 'biff2' | 'xlml' | 'ods' | 'fods' | 'csv' | 'txt' | 'sylk' | 'slk' | 'html' | 'dif' | 'rtf' | 'prn' | 'eth' | 'dbf';
Type of generated workbook 'xlsx'
type CBFunc
type CBFunc = () => void;
Attempts to write or download workbook data to file asynchronously
type ExcelDataType
type ExcelDataType = 'b' | 'n' | 'e' | 's' | 'd' | 'z';
The Excel data type for a cell. b Boolean, n Number, e error, s String, d Date, z Stub
type NumberFormat
type NumberFormat = string | number;
Number Format (either a string or an index to the format table)
type RangeSpec
type RangeSpec = string | Range | CellAddress;
Range specifier (string or range or cell), single-cell lifted to range
type SheetKeys
type SheetKeys = string | MarginInfo | SheetType;
type SheetType
type SheetType = 'sheet' | 'chart';
type WSKeys
type WSKeys = | SheetKeys | ColInfo[] | RowInfo[] | Range[] | ProtectInfo | AutoFilterInfo;
type WSSpec
type WSSpec = string | number | WorkSheet;
Worksheet specifier (string, number, worksheet)
Package Files (1)
Dependencies (7)
Dev Dependencies (17)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/xlsx
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/xlsx)
- HTML<a href="https://www.jsdocs.io/package/xlsx"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2466 ms. - Missing or incorrect documentation? Open an issue for this package.