sheetjs/types/index.d.ts

904 lines
23 KiB
TypeScript
Raw Normal View History

/* index.d.ts (C) 2015-present SheetJS and contributors */
// TypeScript Version: 2.2
2022-02-12 06:31:47 +00:00
// import * as CFB from "cfb";
// import * as SSF from "ssf";
/** Version string */
export const version: string;
/** SSF Formatter Library */
2022-02-12 06:31:47 +00:00
// export { SSF };
export const SSF: any;
2017-07-05 10:24:46 +00:00
/** CFB Library */
2022-02-12 06:31:47 +00:00
// export { CFB };
export const CFB: any;
/** ESM ONLY! Set internal `fs` instance */
export function set_fs(fs: any): void;
/** ESM ONLY! Set internal codepage tables */
export function set_cptable(cptable: any): void;
/** NODE ONLY! Attempts to read filename and parse */
2017-05-13 23:37:23 +00:00
export function readFile(filename: string, opts?: ParsingOptions): WorkBook;
2017-03-12 07:21:11 +00:00
/** Attempts to parse data */
2017-05-13 23:37:23 +00:00
export function read(data: any, opts?: ParsingOptions): WorkBook;
/** Attempts to write or download workbook data to file */
2017-05-13 23:37:23 +00:00
export function writeFile(data: WorkBook, filename: string, opts?: WritingOptions): any;
2022-02-14 01:28:13 +00:00
/** Attempts to write or download workbook data to XLSX file */
export function writeFileXLSX(data: WorkBook, filename: string, opts?: WritingOptions): any;
2021-09-21 01:09:24 +00:00
/** Attempts to write or download workbook data to file asynchronously */
type CBFunc = () => void;
export function writeFileAsync(filename: string, data: WorkBook, opts: WritingOptions | CBFunc, cb?: CBFunc): any;
2017-03-12 07:21:11 +00:00
/** Attempts to write the workbook data */
export function write(data: WorkBook, opts: WritingOptions): any;
2022-02-14 01:28:13 +00:00
/** Attempts to write the workbook data as XLSX */
export function writeXLSX(data: WorkBook, opts: WritingOptions): any;
2017-03-12 07:21:11 +00:00
2017-06-19 07:14:14 +00:00
/** Utility Functions */
export const utils: XLSX$Utils;
2017-06-19 07:14:14 +00:00
/** Stream Utility Functions */
export const stream: StreamUtils;
/** Number Format (either a string or an index to the format table) */
export type NumberFormat = string | number;
2020-01-28 01:20:38 +00:00
/** Worksheet specifier (string, number, worksheet) */
export type WSSpec = string | number | WorkSheet;
/** Range specifier (string or range or cell), single-cell lifted to range */
export type RangeSpec = string | Range | CellAddress;
/** Basic File Properties */
2017-05-13 23:37:23 +00:00
export interface Properties {
/** Summary tab "Title" */
Title?: string;
/** Summary tab "Subject" */
Subject?: string;
/** Summary tab "Author" */
Author?: string;
/** Summary tab "Manager" */
Manager?: string;
/** Summary tab "Company" */
Company?: string;
/** Summary tab "Category" */
Category?: string;
/** Summary tab "Keywords" */
Keywords?: string;
/** Summary tab "Comments" */
Comments?: string;
/** Statistics tab "Last saved by" */
LastAuthor?: string;
/** Statistics tab "Created" */
CreatedDate?: Date;
}
/** Other supported properties */
export interface FullProperties extends Properties {
2017-05-12 21:46:46 +00:00
ModifiedDate?: Date;
Application?: string;
AppVersion?: string;
DocSecurity?: string;
HyperlinksChanged?: boolean;
SharedDoc?: boolean;
LinksUpToDate?: boolean;
ScaleCrop?: boolean;
Worksheets?: number;
SheetNames?: string[];
ContentStatus?: string;
LastPrinted?: string;
Revision?: string | number;
Version?: string;
Identifier?: string;
Language?: string;
}
export interface CommonOptions {
2017-03-12 07:21:11 +00:00
/**
* If true, throw errors when features are not understood
* @default false
2017-03-12 07:21:11 +00:00
*/
WTF?: boolean;
/**
* When reading a file with VBA macros, expose CFB blob to `vbaraw` field
* When writing BIFF8/XLSB/XLSM, reseat `vbaraw` and export to file
* @default false
*/
bookVBA?: 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)
* @default false
*/
cellDates?: boolean;
2020-01-28 01:20:38 +00:00
/**
* Create cell objects for stub cells
* @default false
*/
sheetStubs?: boolean;
/**
* When reading a file, save style/theme info to the .s field
* When writing a file, export style/theme info
* @default false
*/
cellStyles?: boolean;
2020-01-28 01:20:38 +00:00
/**
* If defined and file is encrypted, use password
* @default ''
*/
password?: string;
}
export interface DateNFOption {
/** Use specified date format */
dateNF?: NumberFormat;
}
/** Options for read and readFile */
export interface ParsingOptions extends CommonOptions {
/** Input data encoding */
type?: 'base64' | 'binary' | 'buffer' | 'file' | 'array' | 'string';
2017-03-12 07:21:11 +00:00
/** Default codepage */
codepage?: number;
2017-03-12 07:21:11 +00:00
/**
* Save formulae to the .f field
* @default true
*/
cellFormula?: boolean;
2017-03-12 07:21:11 +00:00
/**
* Parse rich text and save HTML to the .h field
* @default true
*/
cellHTML?: boolean;
2017-03-12 07:21:11 +00:00
/**
* Save number format string to the .z field
* @default false
*/
cellNF?: boolean;
2017-03-12 07:21:11 +00:00
/**
* Generate formatted text to the .w field
* @default true
2017-03-12 07:21:11 +00:00
*/
cellText?: boolean;
/** Override default date format (code 14) */
dateNF?: string;
2017-03-12 07:21:11 +00:00
2021-11-09 00:31:56 +00:00
/** Field Separator ("Delimiter" override) */
FS?: string;
2017-03-12 07:21:11 +00:00
/**
* If >0, read the first sheetRows rows
* @default 0
*/
sheetRows?: number;
2017-03-12 07:21:11 +00:00
/**
* If true, parse calculation chains
* @default false
*/
bookDeps?: boolean;
2017-03-12 07:21:11 +00:00
/**
* If true, add raw files to book object
* @default false
*/
bookFiles?: boolean;
2017-03-12 07:21:11 +00:00
/**
* If true, only parse enough to get book metadata
* @default false
*/
bookProps?: boolean;
2017-03-12 07:21:11 +00:00
/**
* If true, only parse enough to get the sheet names
* @default false
*/
bookSheets?: boolean;
2017-03-12 07:21:11 +00:00
2020-01-28 01:20:38 +00:00
/** If specified, only parse the specified sheets or sheet names */
sheets?: number | string | Array<number | string>;
/** If true, plaintext parsing will not parse values */
raw?: boolean;
2022-02-13 09:35:34 +00:00
/** If true, preserve _xlfn. prefixes in formula function names */
xlfn?: boolean;
dense?: boolean;
2022-02-13 09:35:34 +00:00
PRN?: boolean;
2017-03-12 07:21:11 +00:00
}
export interface SheetOption {
/**
* Name of Worksheet (for single-sheet formats)
* @default ''
*/
sheet?: string;
}
/** Options for write and writeFile */
export interface WritingOptions extends CommonOptions, SheetOption {
/** Output data encoding */
type?: 'base64' | 'binary' | 'buffer' | 'file' | 'array' | 'string';
2017-03-12 07:21:11 +00:00
/**
* Generate Shared String Table
* @default false
*/
bookSST?: boolean;
/**
* File format of generated workbook
2017-03-12 07:21:11 +00:00
* @default 'xlsx'
*/
bookType?: BookType;
2017-03-12 07:21:11 +00:00
/**
* Use ZIP compression for ZIP-based formats
* @default false
*/
compression?: boolean;
/**
* Suppress "number stored as text" errors in generated files
* @default true
*/
ignoreEC?: boolean;
/** Override workbook properties on save */
Props?: Properties;
/** Base64 encoding of NUMBERS base for exports */
numbers?: string;
}
/** Workbook Object */
2017-05-13 23:37:23 +00:00
export interface WorkBook {
/**
* A dictionary of the worksheets in the workbook.
* Use SheetNames to reference these.
*/
2017-05-13 23:37:23 +00:00
Sheets: { [sheet: string]: WorkSheet };
/** Ordered list of the sheet names in the workbook */
SheetNames: string[];
/** Standard workbook Properties */
Props?: FullProperties;
/** Custom workbook Properties */
Custprops?: object;
Workbook?: WBProps;
vbaraw?: any;
2022-07-08 22:31:08 +00:00
/** Original file type (when parsed with `read` or `readFile`) */
bookType?: BookType;
}
export interface SheetProps {
2020-06-26 19:51:23 +00:00
/** Name of Sheet */
name?: string;
2020-06-26 19:51:23 +00:00
/** Sheet Visibility (0=Visible 1=Hidden 2=VeryHidden) */
Hidden?: 0 | 1 | 2;
/** Name of Document Module in associated VBA Project */
CodeName?: string;
}
2017-06-19 07:14:14 +00:00
/** Defined Name Object */
export interface DefinedName {
2017-06-19 07:14:14 +00:00
/** Name */
Name: string;
2017-06-19 07:14:14 +00:00
/** Reference */
Ref: string;
2017-06-19 07:14:14 +00:00
/** Scope (undefined for workbook scope) */
Sheet?: number;
2017-06-19 07:14:14 +00:00
/** Name comment */
Comment?: string;
}
/** Workbook-Level Attributes */
export interface WBProps {
/** Sheet Properties */
Sheets?: SheetProps[];
/** Defined Names */
Names?: DefinedName[];
/** Workbook Views */
Views?: WBView[];
/** Other Workbook Properties */
WBProps?: WorkbookProperties;
}
/** Workbook View */
export interface WBView {
/** Right-to-left mode */
RTL?: boolean;
}
/** Other Workbook Properties */
export interface WorkbookProperties {
/** Worksheet Epoch (1904 if true, 1900 if false) */
date1904?: boolean;
2017-06-03 07:19:09 +00:00
/** Warn or strip personally identifying info on save */
filterPrivacy?: boolean;
/** Name of Document Module in associated VBA Project */
CodeName?: string;
}
/** DBF Field Header */
export interface DBFField {
/** Original Field Name */
name?: string;
/** Field Type */
type?: string;
/** Field Length */
len?: number;
/** Field Decimal Count */
dec?: number;
}
2017-06-19 07:14:14 +00:00
/** Column Properties Object */
2017-05-13 23:37:23 +00:00
export interface ColInfo {
/* --- visibility --- */
/** if true, the column is hidden */
hidden?: boolean;
/* --- column width --- */
/** width in Excel's "Max Digit Width", width*256 is integral */
width?: number;
/** width in screen pixels */
2017-05-12 21:46:24 +00:00
wpx?: number;
/** width in "characters" */
2017-05-12 21:46:24 +00:00
wch?: number;
/** outline / group level */
level?: number;
/** Excel's "Max Digit Width" unit, always integral */
MDW?: number;
/** DBF Field Header */
DBF?: DBFField;
2017-05-12 21:46:24 +00:00
}
2017-06-19 07:14:14 +00:00
/** Row Properties Object */
2017-05-13 23:37:23 +00:00
export interface RowInfo {
/* --- visibility --- */
/** if true, the column is hidden */
hidden?: boolean;
/* --- row height --- */
/** height in screen pixels */
2017-05-12 21:46:24 +00:00
hpx?: number;
/** height in points */
2017-05-12 21:46:24 +00:00
hpt?: number;
/** outline / group level */
level?: number;
2017-05-12 21:46:24 +00:00
}
/**
* Write sheet protection properties.
*/
2017-05-13 23:37:23 +00:00
export interface ProtectInfo {
2017-05-12 21:46:24 +00:00
/**
* The password for formats that support password-protected sheets
* (XLSX/XLSB/XLS). The writer uses the XOR obfuscation method.
*/
password?: string;
/**
* Select locked cells
* @default: true
*/
selectLockedCells?: boolean;
/**
* Select unlocked cells
* @default: true
*/
selectUnlockedCells?: boolean;
/**
* Format cells
* @default: false
*/
formatCells?: boolean;
/**
* Format columns
* @default: false
*/
formatColumns?: boolean;
/**
* Format rows
* @default: false
*/
formatRows?: boolean;
/**
* Insert columns
* @default: false
*/
insertColumns?: boolean;
/**
* Insert rows
* @default: false
*/
insertRows?: boolean;
/**
* Insert hyperlinks
* @default: false
*/
insertHyperlinks?: boolean;
/**
* Delete columns
* @default: false
*/
deleteColumns?: boolean;
/**
* Delete rows
* @default: false
*/
deleteRows?: boolean;
/**
* Sort
* @default: false
*/
sort?: boolean;
/**
* Filter
* @default: false
*/
autoFilter?: boolean;
/**
* Use PivotTable reports
* @default: false
*/
pivotTables?: boolean;
/**
* Edit objects
* @default: true
*/
objects?: boolean;
/**
* Edit scenarios
* @default: true
*/
scenarios?: boolean;
}
/** Page Margins -- see Excel Page Setup .. Margins diagram for explanation */
export interface MarginInfo {
/** Left side margin (inches) */
left?: number;
/** Right side margin (inches) */
right?: number;
/** Top side margin (inches) */
top?: number;
/** Bottom side margin (inches) */
bottom?: number;
/** Header top margin (inches) */
header?: number;
/** Footer bottom height (inches) */
footer?: number;
}
export type SheetType = 'sheet' | 'chart';
export type SheetKeys = string | MarginInfo | SheetType;
/** General object representing a Sheet (worksheet or chartsheet) */
2017-05-13 23:37:23 +00:00
export interface Sheet {
/**
* Indexing with a cell address string maps to a cell object
* Special keys start with '!'
*/
[cell: string]: CellObject | SheetKeys | any;
/** Sheet type */
'!type'?: SheetType;
/** Sheet Range */
2017-05-12 21:46:24 +00:00
'!ref'?: string;
/** Page Margins */
'!margins'?: MarginInfo;
}
/** AutoFilter properties */
export interface AutoFilterInfo {
/** Range of the AutoFilter table */
ref: string;
2017-05-12 21:46:24 +00:00
}
2020-01-28 01:20:38 +00:00
export type WSKeys = SheetKeys | ColInfo[] | RowInfo[] | Range[] | ProtectInfo | AutoFilterInfo;
2017-05-12 21:46:24 +00:00
2017-06-19 07:14:14 +00:00
/** Worksheet Object */
2017-05-13 23:37:23 +00:00
export interface WorkSheet extends Sheet {
/**
* Indexing with a cell address string maps to a cell object
* Special keys start with '!'
*/
[cell: string]: CellObject | WSKeys | any;
2017-06-19 07:14:14 +00:00
/** Column Info */
2017-05-13 23:37:23 +00:00
'!cols'?: ColInfo[];
2017-06-19 07:14:14 +00:00
/** Row Info */
2017-05-13 23:37:23 +00:00
'!rows'?: RowInfo[];
2017-06-19 07:14:14 +00:00
/** Merge Ranges */
2017-05-13 23:37:23 +00:00
'!merges'?: Range[];
2017-06-19 07:14:14 +00:00
/** Worksheet Protection info */
2017-05-13 23:37:23 +00:00
'!protect'?: ProtectInfo;
2017-06-19 07:14:14 +00:00
/** AutoFilter info */
'!autofilter'?: AutoFilterInfo;
}
2020-01-28 01:20:38 +00:00
/**
* Worksheet Object with CellObject type
*
* The normal Worksheet type uses indexer of type `any` -- this enforces CellObject
*/
export interface StrictWS { [addr: string]: CellObject; }
/**
2017-05-12 21:46:39 +00:00
* The Excel data type for a cell.
2017-06-19 07:14:14 +00:00
* b Boolean, n Number, e error, s String, d Date, z Stub
2017-05-12 21:46:39 +00:00
*/
export type ExcelDataType = 'b' | 'n' | 'e' | 's' | 'd' | 'z';
/**
* Type of generated workbook
* @default 'xlsx'
*/
2022-04-11 04:11:47 +00:00
export type BookType = 'xlsx' | 'xlsm' | 'xlsb' | 'xls' | 'xla' | 'biff8' | 'biff5' | 'biff2' | 'xlml' | 'ods' | 'fods' | 'csv' | 'txt' | 'sylk' | 'slk' | 'html' | 'dif' | 'rtf' | 'prn' | 'eth' | 'dbf' | 'numbers';
2017-06-19 07:14:14 +00:00
/** Comment element */
export interface Comment {
/** Author of the comment block */
a?: string;
/** Plaintext of the comment */
t: string;
/** If true, mark the comment as a part of a thread */
T?: boolean;
}
2020-01-28 01:20:38 +00:00
/** Cell comments */
export interface Comments extends Array<Comment> {
/** Hide comment by default */
hidden?: boolean;
}
2017-06-19 07:14:14 +00:00
/** Link object */
export interface Hyperlink {
/** Target of the link (HREF) */
Target: string;
/** Plaintext tooltip to display when mouse is over cell */
Tooltip?: string;
}
2017-06-19 07:14:14 +00:00
/** Worksheet Cell Object */
export interface CellObject {
/** The raw value of the cell. Can be omitted if a formula is specified */
v?: string | number | boolean | Date;
/** Formatted text (if applicable) */
2017-03-12 07:21:11 +00:00
w?: string;
/**
2017-05-12 21:46:39 +00:00
* The Excel Data Type of the cell.
* b Boolean, n Number, e Error, s String, d Date, z Empty
2017-05-12 21:46:39 +00:00
*/
t: ExcelDataType;
2017-03-12 07:21:11 +00:00
/** Cell formula (if applicable) */
2017-03-12 07:21:11 +00:00
f?: string;
/** Range of enclosing array if formula is array formula (if applicable) */
2017-03-12 07:21:11 +00:00
F?: string;
/** Rich text encoding (if applicable) */
r?: any;
/** HTML rendering of the rich text (if applicable) */
2017-03-12 07:21:11 +00:00
h?: string;
/** Comments associated with the cell */
2020-01-28 01:20:38 +00:00
c?: Comments;
/** Number format string associated with the cell (if requested) */
z?: NumberFormat;
/** Cell hyperlink object (.Target holds link, .tooltip is tooltip) */
l?: Hyperlink;
/** The style/theme of the cell (if applicable) */
s?: any;
}
2017-06-19 07:14:14 +00:00
/** Simple Cell Address */
export interface CellAddress {
2017-03-12 07:21:11 +00:00
/** Column number */
c: number;
2017-03-12 07:21:11 +00:00
/** Row number */
r: number;
}
2020-01-28 01:20:38 +00:00
/** Range object (representing ranges like "A1:B2") */
2017-05-13 23:37:23 +00:00
export interface Range {
2017-03-12 07:21:11 +00:00
/** Starting cell */
s: CellAddress;
2017-03-12 07:21:11 +00:00
/** Ending cell */
e: CellAddress;
}
export interface Sheet2CSVOpts extends DateNFOption {
/** Field Separator ("delimiter") */
FS?: string;
/** Record Separator ("row separator") */
RS?: string;
/** Remove trailing field separators in each record */
strip?: boolean;
/** Include blank lines in the CSV output */
blankrows?: boolean;
/** Skip hidden rows and columns in the CSV output */
skipHidden?: boolean;
/** Force quotes around fields */
forceQuotes?: boolean;
/** if true, return raw numbers; if false, return formatted numbers */
rawNumbers?: boolean;
}
export interface OriginOption {
/** Top-Left cell for operation (CellAddress or A1 string or row) */
origin?: number | string | CellAddress;
}
export interface Sheet2HTMLOpts {
/** TABLE element id attribute */
id?: string;
2017-06-19 07:14:14 +00:00
/** Add contenteditable to every cell */
editable?: boolean;
2017-06-19 07:14:14 +00:00
/** Header HTML */
header?: string;