2015-06-03 13:34:42 +00:00
|
|
|
// Type definitions for xlsx
|
|
|
|
// Project: https://github.com/SheetJS/js-xlsx
|
2017-05-12 21:46:24 +00:00
|
|
|
// Definitions by: themauveavenger <https://github.com/themauveavenger/>, Wolfgang Faust <https://github.com/wolfgang42>
|
2016-03-16 15:31:58 +00:00
|
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
2015-06-03 13:34:42 +00:00
|
|
|
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Attempts to read filename and parse */
|
2017-05-12 21:46:46 +00:00
|
|
|
export function readFile(filename: string, opts?: IParsingOptions): IWorkBook;
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Attempts to parse data */
|
2017-05-12 21:46:46 +00:00
|
|
|
export function read(data: any, opts?: IParsingOptions): IWorkBook;
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Attempts to write workbook data to filename */
|
2017-05-12 21:46:46 +00:00
|
|
|
export function writeFile(data: IWorkBook, filename: string, opts?: IWritingOptions): any;
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Attempts to write the workbook data */
|
2017-05-12 21:46:46 +00:00
|
|
|
export function write(data: IWorkBook, opts?: IWritingOptions): any;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
2017-05-12 21:46:46 +00:00
|
|
|
export const utils: IUtils;
|
2016-04-22 21:12:45 +00:00
|
|
|
|
|
|
|
export interface IProperties {
|
2017-05-12 21:46:46 +00:00
|
|
|
LastAuthor?: string;
|
2016-04-22 21:12:45 +00:00
|
|
|
Author?: string;
|
|
|
|
CreatedDate?: Date;
|
2017-05-12 21:46:46 +00:00
|
|
|
ModifiedDate?: Date;
|
2016-04-22 21:12:45 +00:00
|
|
|
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
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
cellFormula?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse rich text and save HTML to the .h field
|
|
|
|
* @default true
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
cellHTML?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save number format string to the .z field
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
cellNF?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save style/theme info to the .s field
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
cellStyles?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Store dates as type d (default is n)
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
cellDates?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create cell objects for stub cells
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
sheetStubs?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If >0, read the first sheetRows rows
|
|
|
|
* @default 0
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
sheetRows?: number;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, parse calculation chains
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
bookDeps?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, add raw files to book object
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
bookFiles?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, only parse enough to get book metadata
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
bookProps?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, only parse enough to get the sheet names
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
bookSheets?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, expose vbaProject.bin to vbaraw field
|
|
|
|
* @default false
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
bookVBA?: boolean;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If defined and file is encrypted, use password
|
|
|
|
* @default ''
|
|
|
|
*/
|
2016-04-22 21:12:45 +00:00
|
|
|
password?: string;
|
2017-03-12 07:21:11 +00:00
|
|
|
}
|
2016-04-22 21:12:45 +00:00
|
|
|
|
2017-03-12 07:21:11 +00:00
|
|
|
export interface IWritingOptions {
|
2016-04-22 21:12:45 +00:00
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* Output data encoding
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
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;
|
2016-04-22 21:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-05-12 21:46:24 +00:00
|
|
|
export interface IColInfo {
|
|
|
|
/**
|
|
|
|
* Excel's "Max Digit Width" unit, always integral
|
|
|
|
*/
|
|
|
|
MDW?: number;
|
|
|
|
/**
|
|
|
|
* width in Excel's "Max Digit Width", width*256 is integral
|
|
|
|
*/
|
|
|
|
width: number;
|
|
|
|
/**
|
|
|
|
* width in screen pixels
|
|
|
|
*/
|
|
|
|
wpx?: number;
|
|
|
|
/**
|
|
|
|
* intermediate character calculation
|
|
|
|
*/
|
|
|
|
wch?: number;
|
|
|
|
/**
|
|
|
|
* if true, the column is hidden
|
|
|
|
*/
|
|
|
|
hidden?: boolean;
|
|
|
|
}
|
|
|
|
export interface IRowInfo {
|
|
|
|
/**
|
|
|
|
* height in screen pixels
|
|
|
|
*/
|
|
|
|
hpx?: number;
|
|
|
|
/**
|
|
|
|
* height in points
|
|
|
|
*/
|
|
|
|
hpt?: number;
|
|
|
|
/**
|
|
|
|
* if true, the column is hidden
|
|
|
|
*/
|
|
|
|
hidden?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write sheet protection properties.
|
|
|
|
*/
|
|
|
|
export interface IProtectInfo {
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* object representing any sheet (worksheet or chartsheet)
|
|
|
|
*/
|
|
|
|
export interface ISheet {
|
|
|
|
'!ref'?: string;
|
|
|
|
'!margins'?: {
|
|
|
|
left: number,
|
|
|
|
right: number,
|
|
|
|
top: number,
|
|
|
|
bottom: number,
|
|
|
|
header: number,
|
|
|
|
footer: number,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-04-22 21:12:45 +00:00
|
|
|
/**
|
|
|
|
* object representing the worksheet
|
|
|
|
*/
|
2017-05-12 21:46:24 +00:00
|
|
|
export interface IWorkSheet extends ISheet {
|
2017-03-14 18:02:19 +00:00
|
|
|
[cell: string]: IWorkSheetCell | any;
|
2017-05-12 21:46:24 +00:00
|
|
|
'!cols'?: IColInfo[];
|
|
|
|
'!rows'?: IRowInfo[];
|
|
|
|
'!merges'?: IRange[];
|
|
|
|
'!protect'?: IProtectInfo;
|
|
|
|
'!autofilter'?: {ref: string};
|
2016-04-22 21:12:45 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 21:46:31 +00:00
|
|
|
/**
|
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
|
|
|
|
*/
|
2017-05-12 21:46:31 +00:00
|
|
|
export type ExcelDataType = 'b' | 'n' | 'e' | 's' | 'd';
|
|
|
|
|
2016-04-22 21:12:45 +00:00
|
|
|
export interface IWorkSheetCell {
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* The raw value of the cell.
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
2017-03-12 07:21:11 +00:00
|
|
|
v: string | number | boolean | Date;
|
2016-04-22 21:12:45 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* Formatted text (if applicable)
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
2017-03-12 07:21:11 +00:00
|
|
|
w?: string;
|
2016-04-22 21:12:45 +00:00
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
*/
|
2017-05-12 21:46:31 +00:00
|
|
|
t: ExcelDataType;
|
2017-03-12 07:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Cell formula (if applicable)
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
2017-03-12 07:21:11 +00:00
|
|
|
f?: string;
|
2016-04-22 21:12:45 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* Range of enclosing array if formula is array formula (if applicable)
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
2017-03-12 07:21:11 +00:00
|
|
|
F?: string;
|
2016-04-22 21:12:45 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* Rich text encoding (if applicable)
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
2017-03-12 07:21:11 +00:00
|
|
|
r?: string;
|
2016-04-22 21:12:45 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* HTML rendering of the rich text (if applicable)
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
2017-03-12 07:21:11 +00:00
|
|
|
h?: string;
|
2016-04-22 21:12:45 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* Comments associated with the cell **
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
|
|
|
c?: string;
|
|
|
|
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* Number format string associated with the cell (if requested)
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
|
|
|
z?: string;
|
|
|
|
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* Cell hyperlink object (.Target holds link, .tooltip is tooltip)
|
2016-04-22 21:12:45 +00:00
|
|
|
*/
|
2017-03-14 18:02:19 +00:00
|
|
|
l?: Object;
|
2015-06-03 13:34:42 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-12 07:21:11 +00:00
|
|
|
* The style/theme of the cell (if applicable)
|
2015-06-03 13:34:42 +00:00
|
|
|
*/
|
2017-03-14 18:02:19 +00:00
|
|
|
s?: Object;
|
2016-04-22 21:12:45 +00:00
|
|
|
}
|
2015-06-03 13:34:42 +00:00
|
|
|
|
2016-08-11 20:18:32 +00:00
|
|
|
export interface ICell {
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Column number */
|
2016-08-11 20:18:32 +00:00
|
|
|
c: number;
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Row number */
|
2016-08-11 20:18:32 +00:00
|
|
|
r: number;
|
|
|
|
}
|
|
|
|
|
2016-11-22 23:08:50 +00:00
|
|
|
export interface IRange {
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Starting cell */
|
2016-11-22 23:08:50 +00:00
|
|
|
s: ICell;
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Ending cell */
|
2016-11-22 23:08:50 +00:00
|
|
|
e: ICell;
|
|
|
|
}
|
|
|
|
|
2016-04-22 21:12:45 +00:00
|
|
|
export interface IUtils {
|
2017-04-14 19:16:23 +00:00
|
|
|
/** converts an array of arrays of JS data to a worksheet. */
|
2017-05-12 21:46:39 +00:00
|
|
|
aoa_to_sheet<T>(data: T[], opts?: any): IWorkSheet;
|
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 */
|
2017-05-12 21:46:39 +00:00
|
|
|
sheet_to_json<T>(worksheet: IWorkSheet, opts?: {
|
2016-08-11 20:18:32 +00:00
|
|
|
raw?: boolean;
|
|
|
|
range?: any;
|
|
|
|
header?: "A"|number|string[];
|
2017-05-12 21:46:39 +00:00
|
|
|
}): T[];
|
2017-03-12 07:21:11 +00:00
|
|
|
/** Generates delimiter-separated-values output */
|
2017-02-07 12:21:31 +00:00
|
|
|
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) */
|
2017-05-12 21:46:39 +00:00
|
|
|
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 */
|
2016-11-22 23:08:50 +00:00
|
|
|
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 */
|
2016-11-22 23:08:50 +00:00
|
|
|
decode_range(range: string): IRange;
|
2015-06-03 13:34:42 +00:00
|
|
|
}
|