xsheetjs/types/index.d.ts

628 lines
15 KiB
TypeScript
Raw Normal View History

/* index.d.ts (C) 2015-present SheetJS and contributors */
// TypeScript Version: 2.2
/** Version string */
export const version: string;
2017-03-12 07:21:11 +00:00
/** 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;
/** NODE ONLY! Attempts to write workbook data to filename */
2017-05-13 23:37:23 +00:00
export function writeFile(data: WorkBook, filename: string, opts?: WritingOptions): any;
2017-03-12 07:21:11 +00:00
/** Attempts to write the workbook data */
2017-05-13 23:37:23 +00:00
export function write(data: WorkBook, opts?: WritingOptions): any;
2017-03-12 07:21:11 +00:00
2017-05-13 23:37:23 +00:00
export const utils: Utils;
export const stream: StreamUtils;
/** Number Format (either a string or an index to the format table) */
export type NumberFormat = string | number;
/** 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, store dates as type d (default is n)
* When writing XLSX/XLSM file, use native date (default uses date codes)
* @default false
*/
cellDates?: boolean;
}
/** Options for read and readFile */
export interface ParsingOptions extends CommonOptions {
/** Input data encoding */
type?: 'base64' | 'binary' | 'buffer' | 'file' | 'array';
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
/**
* Save style/theme info to the .s field
* @default false
*/
cellStyles?: 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
/**
* Create cell objects for stub cells
* @default false
*/
sheetStubs?: boolean;
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
/**
* If true, expose vbaProject.bin to vbaraw field
* @default false
*/
bookVBA?: boolean;
2017-03-12 07:21:11 +00:00
/**
* If defined and file is encrypted, use password
* @default ''
*/
password?: string;
2017-03-12 07:21:11 +00:00
}
/** Options for write and writeFile */
export interface WritingOptions extends CommonOptions {
/** Output data encoding */
2017-03-12 07:21:11 +00:00
type?: 'base64' | 'binary' | 'buffer' | 'file';
/**
* 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
/**
* Name of Worksheet (for single-sheet formats)
2017-03-12 07:21:11 +00:00
* @default ''
*/
sheet?: string;
/**
* Use ZIP compression for ZIP-based formats
* @default false
*/
compression?: boolean;
/** Override workbook properties on save */
Props?: Properties;
}
/** 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[];
/**
* an object storing the standard properties. wb.Custprops stores custom properties.
* Since the XLS standard properties deviate from the XLSX standard, XLS parsing stores core properties in both places.
*/
Props?: FullProperties;
Workbook?: WBProps;
}
export interface SheetProps {
/** Sheet Visibility (0=Visible 1=Hidden 2=VeryHidden) */
Hidden?: 0 | 1 | 2;
}
export interface DefinedName {
Name: string;
Ref: string;
Sheet?: number;
Comment?: string;
}
/** Workbook-Level Attributes */
export interface WBProps {
/** Sheet Properties */
Sheets?: SheetProps[];
/** Defined Names */
Names?: DefinedName[];
}
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;
/** Excel's "Max Digit Width" unit, always integral */
MDW?: number;
2017-05-12 21:46:24 +00:00
}
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;
}
/**
* 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
}
export type WSKeys = SheetKeys | ColInfo[] | RowInfo[] | Range[] | ProtectInfo | AutoFilterInfo;
2017-05-12 21:46:24 +00:00
/**
* object representing the worksheet
*/
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-05-13 23:37:23 +00:00
'!cols'?: ColInfo[];
'!rows'?: RowInfo[];
'!merges'?: Range[];
'!protect'?: ProtectInfo;
'!autofilter'?: AutoFilterInfo;
}
/**
2017-05-12 21:46:39 +00:00
* The Excel data type for a cell.
* b Boolean, n Number, e error, s String, d Date
*/
export type ExcelDataType = 'b' | 'n' | 'e' | 's' | 'd' | 'z';
/**
* Type of generated workbook
* @default 'xlsx'
*/
export type BookType = 'xlsx' | 'xlsm' | 'xlsb' | 'biff2' | 'xlml' | 'ods' | 'fods' | 'csv' | 'txt' | 'sylk' | 'html' | 'dif' | 'prn';
export interface Comment {
/** Author of the comment block */
a?: string;
/** Plaintext of the comment */
t: string;
}
export interface Hyperlink {
/** Target of the link (HREF) */
Target: string;
/** Plaintext tooltip to display when mouse is over cell */
Tooltip?: string;
}
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 */
c?: Comment[];
/** 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?: object;
}
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;
}
/**
* 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 {
/** Field Separator ("delimiter") */
FS?: string;
/** Record Separator ("row separator") */
RS?: string;
/** Use specified date format */
dateNF?: NumberFormat;
}
export interface Sheet2HTMLOpts {
editable?: boolean;
header?: string;
footer?: string;
}
export interface Sheet2JSONOpts {
/** Use specified date format */
dateNF?: NumberFormat;
header?: "A"|number|string[];
range?: any;
raw?: boolean;
}
export interface AOA2SheetOpts {
/** Use specified date format */
dateNF?: NumberFormat;
/**
* Store dates as type d (default is n)
* @default false
*/
cellDates?: boolean;
/**
* Create cell objects for stub cells
* @default false
*/
sheetStubs?: boolean;
}
export interface JSON2SheetOpts {
/** Use specified date format */
dateNF?: NumberFormat;
}
export interface Table2SheetOpts {
/** Use specified date format */
dateNF?: NumberFormat;
}
/**
* General utilities
*/
2017-05-13 23:37:23 +00:00
export interface Utils {
/* --- Import Functions --- */
/** Converts an array of arrays of JS data to a worksheet. */
aoa_to_sheet<T>(data: T[][], opts?: AOA2SheetOpts): WorkSheet;
aoa_to_sheet(data: any[][], opts?: AOA2SheetOpts): WorkSheet;
/** Converts an array of JS objects to a worksheet. */
json_to_sheet<T>(data: T[], opts?: JSON2SheetOpts): WorkSheet;
json_to_sheet(data: any[], opts?: JSON2SheetOpts): WorkSheet;
/** Converts a TABLE DOM element to a worksheet. */
table_to_sheet(data: HTMLTableElement, opts?: Table2SheetOpts): WorkSheet;
table_to_book(data: HTMLTableElement, opts?: Table2SheetOpts): WorkBook;
/* --- Export Functions --- */
2017-04-14 20:37:22 +00:00
2017-03-12 07:21:11 +00:00
/** Converts a worksheet object to an array of JSON objects */
sheet_to_json<T>(worksheet: WorkSheet, opts?: Sheet2JSONOpts): T[];
sheet_to_json(worksheet: WorkSheet, opts?: Sheet2JSONOpts): any[][];
sheet_to_json(worksheet: WorkSheet, opts?: Sheet2JSONOpts): any[];
2017-03-12 07:21:11 +00:00
/** Generates delimiter-separated-values output */
sheet_to_csv(worksheet: WorkSheet, options?: Sheet2CSVOpts): string;
/** Generates HTML */
sheet_to_html(worksheet: WorkSheet, options?: Sheet2HTMLOpts): string;
2017-03-12 07:21:11 +00:00
/** Generates a list of the formulae (with value fallbacks) */
sheet_to_formulae(worksheet: WorkSheet): string[];
2017-03-12 07:21:11 +00:00
/* --- Cell Address Utilities --- */
2017-03-12 07:21:11 +00:00
/** Converts 0-indexed cell address to A1 form */
encode_cell(cell: CellAddress): string;
2017-03-12 07:21:11 +00:00
/** Converts 0-indexed row to A1 form */
encode_row(row: number): string;
2017-03-12 07:21:11 +00:00
/** Converts 0-indexed column to A1 form */
encode_col(col: number): string;
2017-03-12 07:21:11 +00:00
/** Converts 0-indexed range to A1 form */
encode_range(s: CellAddress, e: CellAddress): string;
encode_range(r: Range): string;
2017-03-12 07:21:11 +00:00
/** Converts A1 cell address to 0-indexed form */
decode_cell(address: string): CellAddress;
2017-03-12 07:21:11 +00:00
/** Converts A1 row to 0-indexed form */
decode_row(row: string): number;
2017-03-12 07:21:11 +00:00
/** Converts A1 column to 0-indexed form */
decode_col(col: string): number;
2017-03-12 07:21:11 +00:00
/** Converts A1 range to 0-indexed form */
2017-05-13 23:37:23 +00:00
decode_range(range: string): Range;
}
/** NODE ONLY! these return Readable Streams */
export interface StreamUtils {
/** CSV output stream, generate one line at a time */
to_csv(sheet: WorkSheet, opts?: Sheet2CSVOpts): any;
/** HTML output stream, generate one line at a time */
to_html(sheet: WorkSheet, opts?: Sheet2HTMLOpts): any;
}