xsheetjs/index.d.ts

288 lines
6.5 KiB
TypeScript
Raw Normal View History

// Type definitions for xlsx
// Project: https://github.com/SheetJS/js-xlsx
// Definitions by: themauveavenger <https://github.com/themauveavenger/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
2017-03-12 07:21:11 +00:00
/** Attempts to read filename and parse */
export declare function readFile(filename: string, opts?: IParsingOptions): IWorkBook;
2017-03-12 07:21:11 +00:00
/** Attempts to parse data */
export declare function read(data: any, opts?: IParsingOptions): IWorkBook;
2017-03-12 07:21:11 +00:00
/** Attempts to write workbook data to filename */
export declare function writeFile(data: IWorkBook, filename: string, opts?: IWritingOptions): any;
/** Attempts to write the workbook data */
export declare function write(data: IWorkBook, opts?: IWritingOptions): any;
export declare var utils: IUtils;
export interface IProperties {
LastAuthor?: string
Author?: string;
CreatedDate?: Date;
ModifiedDate?: Date
Application?: string;
AppVersion?: string;
Company?: string;
DocSecurity?: string;
Manager?: string;
HyperlinksChanged?: boolean;
SharedDoc?: boolean;
LinksUpToDate?: boolean;
ScaleCrop?: boolean;
Worksheets?: number;
SheetNames?: string[];
}
export interface IParsingOptions {
2017-03-12 07:21:11 +00:00
/**
* Input data encoding
*/
type?: 'base64' | 'binary' | 'buffer' | 'array' | 'file';
/**
* 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
/**
* Store dates as type d (default is n)
* @default false
*/
cellDates?: boolean;
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
}
2017-03-12 07:21:11 +00:00
export interface IWritingOptions {
/**
2017-03-12 07:21:11 +00:00
* Output data encoding
*/
2017-03-12 07:21:11 +00:00
type?: 'base64' | 'binary' | 'buffer' | 'file';
/**
* Store dates as type d (default is n)
* @default false
*/
cellDates?: boolean;
/**
* Generate Shared String Table
* @default false
*/
bookSST?: boolean;
/**
* Type of Workbook
* @default 'xlsx'
*/
bookType?: 'xlsx' | 'xlsm' | 'xlsb' | 'ods' | 'biff2' | 'fods' | 'csv';
/**
* Name of Worksheet for single-sheet formats
* @default ''
*/
sheet?: string;
/**
* Use ZIP compression for ZIP-based formats
* @default false
*/
compression?: boolean;
}
export interface IWorkBook {
/**
* A dictionary of the worksheets in the workbook.
* Use SheetNames to reference these.
*/
Sheets: { [sheet: string]: IWorkSheet };
/**
* 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: IProperties;
}
/**
* object representing the worksheet
*/
export interface IWorkSheet {
2017-03-14 18:02:19 +00:00
[cell: string]: IWorkSheetCell | any;
}
export interface IWorkSheetCell {
/**
2017-03-12 07:21:11 +00:00
* The raw value of the cell.
*/
2017-03-12 07:21:11 +00:00
v: string | number | boolean | Date;
/**
2017-03-12 07:21:11 +00:00
* Formatted text (if applicable)
*/
2017-03-12 07:21:11 +00:00
w?: string;
/**
2017-03-12 07:21:11 +00:00
* The Excel Data Type of the cell.
* b Boolean, n Number, e error, s String, d Date
*/
t: 'b' | 'n' | 'e' | 's' | 'd';
/**
* Cell formula (if applicable)
*/
2017-03-12 07:21:11 +00:00
f?: string;
/**
2017-03-12 07:21:11 +00:00
* Range of enclosing array if formula is array formula (if applicable)
*/
2017-03-12 07:21:11 +00:00
F?: string;
/**
2017-03-12 07:21:11 +00:00
* Rich text encoding (if applicable)
*/
2017-03-12 07:21:11 +00:00
r?: string;
/**
2017-03-12 07:21:11 +00:00
* HTML rendering of the rich text (if applicable)
*/
2017-03-12 07:21:11 +00:00
h?: string;
/**
2017-03-12 07:21:11 +00:00
* Comments associated with the cell **
*/
c?: string;
/**
2017-03-12 07:21:11 +00:00
* Number format string associated with the cell (if requested)
*/
z?: string;
/**
2017-03-12 07:21:11 +00:00
* Cell hyperlink object (.Target holds link, .tooltip is tooltip)
*/
2017-03-14 18:02:19 +00:00
l?: Object;
/**
2017-03-12 07:21:11 +00:00
* The style/theme of the cell (if applicable)
*/
2017-03-14 18:02:19 +00:00
s?: Object;
}
export interface ICell {
2017-03-12 07:21:11 +00:00
/** Column number */
c: number;
2017-03-12 07:21:11 +00:00
/** Row number */
r: number;
}
export interface IRange {
2017-03-12 07:21:11 +00:00
/** Starting cell */
s: ICell;
2017-03-12 07:21:11 +00:00
/** Ending cell */
e: ICell;
}
export interface IUtils {
/** converts an array of arrays of JS data to a worksheet. */
2017-04-14 20:37:22 +00:00
aoa_to_sheet(data: <T>, opts?:any): IWorkSheet;
2017-03-12 07:21:11 +00:00
/** Converts a worksheet object to an array of JSON objects */
sheet_to_json<T>(worksheet:IWorkSheet, opts?: {
raw?: boolean;
range?: any;
header?: "A"|number|string[];
}):T[];
2017-03-12 07:21:11 +00:00
/** Generates delimiter-separated-values output */
sheet_to_csv(worksheet: IWorkSheet, options?: { FS: string, RS: string }): string;
2017-03-12 07:21:11 +00:00
/** Generates a list of the formulae (with value fallbacks) */
sheet_to_formulae(worksheet: IWorkSheet):any;
2017-03-12 07:21:11 +00:00
/** Converts 0-indexed cell address to A1 form */
encode_cell(cell: ICell): string;
/** Converts 0-indexed row to A1 form */
encode_row(row: number): string;
/** Converts 0-indexed column to A1 form */
encode_col(col: number): string;
/** Converts 0-indexed range to A1 form */
encode_range(s: ICell, e: ICell): string;
/** Converts A1 cell address to 0-indexed form */
decode_cell(address: string): ICell;
2017-03-12 07:21:11 +00:00
/** Converts A1 row to 0-indexed form */
decode_row(row: string): number;
/** Converts A1 column to 0-indexed form */
decode_col(col: string): number;
/** Converts A1 range to 0-indexed form */
decode_range(range: string): IRange;
}