UNPKG

22.1 kBTypeScriptView Raw
1declare module 'xlsx-style' {
2 /* index.d.ts (C) 2015-present SheetJS and contributors */
3 // TypeScript Version: 2.2
4 import * as CFB from "cfb";
5 import * as SSF from "ssf";
6
7 /** Version string */
8 export const version: string;
9
10 /** SSF Formatter Library */
11 export { SSF };
12
13 /** CFB Library */
14 export { CFB };
15
16 /** NODE ONLY! Attempts to read filename and parse */
17 export function readFile(filename: string, opts?: ParsingOptions): WorkBook;
18 /** Attempts to parse data */
19 export function read(data: any, opts?: ParsingOptions): WorkBook;
20 /** Attempts to write or download workbook data to file */
21 export function writeFile(data: WorkBook, filename: string, opts?: WritingOptions): any;
22 /** Attempts to write the workbook data */
23 export function write(data: WorkBook, opts?: WritingOptions): any;
24
25 /** Utility Functions */
26 export const utils: XLSX$Utils;
27 /** Stream Utility Functions */
28 export const stream: StreamUtils;
29
30 /** Number Format (either a string or an index to the format table) */
31 export type NumberFormat = string | number;
32
33 /** Basic File Properties */
34 export interface Properties {
35 /** Summary tab "Title" */
36 Title?: string;
37 /** Summary tab "Subject" */
38 Subject?: string;
39 /** Summary tab "Author" */
40 Author?: string;
41 /** Summary tab "Manager" */
42 Manager?: string;
43 /** Summary tab "Company" */
44 Company?: string;
45 /** Summary tab "Category" */
46 Category?: string;
47 /** Summary tab "Keywords" */
48 Keywords?: string;
49 /** Summary tab "Comments" */
50 Comments?: string;
51 /** Statistics tab "Last saved by" */
52 LastAuthor?: string;
53 /** Statistics tab "Created" */
54 CreatedDate?: Date;
55 }
56
57 /** Other supported properties */
58 export interface FullProperties extends Properties {
59 ModifiedDate?: Date;
60 Application?: string;
61 AppVersion?: string;
62 DocSecurity?: string;
63 HyperlinksChanged?: boolean;
64 SharedDoc?: boolean;
65 LinksUpToDate?: boolean;
66 ScaleCrop?: boolean;
67 Worksheets?: number;
68 SheetNames?: string[];
69 ContentStatus?: string;
70 LastPrinted?: string;
71 Revision?: string | number;
72 Version?: string;
73 Identifier?: string;
74 Language?: string;
75 }
76
77 export interface CommonOptions {
78 /**
79 * If true, throw errors when features are not understood
80 * @default false
81 */
82 WTF?: boolean;
83
84 /**
85 * When reading a file with VBA macros, expose CFB blob to `vbaraw` field
86 * When writing BIFF8/XLSB/XLSM, reseat `vbaraw` and export to file
87 * @default false
88 */
89 bookVBA?: boolean;
90
91 /**
92 * When reading a file, store dates as type d (default is n)
93 * When writing XLSX/XLSM file, use native date (default uses date codes)
94 * @default false
95 */
96 cellDates?: boolean;
97
98 /**
99 * When reading a file, save style/theme info to the .s field
100 * When writing a file, export style/theme info
101 * @default false
102 */
103 cellStyles?: boolean;
104 }
105
106 export interface DateNFOption {
107 /** Use specified date format */
108 dateNF?: NumberFormat;
109 }
110
111 /** Options for read and readFile */
112 export interface ParsingOptions extends CommonOptions {
113 /** Input data encoding */
114 type?: 'base64' | 'binary' | 'buffer' | 'file' | 'array' | 'string';
115
116 /** Default codepage */
117 codepage?: number;
118
119 /**
120 * Save formulae to the .f field
121 * @default true
122 */
123 cellFormula?: boolean;
124
125 /**
126 * Parse rich text and save HTML to the .h field
127 * @default true
128 */
129 cellHTML?: boolean;
130
131 /**
132 * Save number format string to the .z field
133 * @default false
134 */
135 cellNF?: boolean;
136
137 /**
138 * Generate formatted text to the .w field
139 * @default true
140 */
141 cellText?: boolean;
142
143 /** Override default date format (code 14) */
144 dateNF?: string;
145
146 /**
147 * Create cell objects for stub cells
148 * @default false
149 */
150 sheetStubs?: boolean;
151
152 /**
153 * If >0, read the first sheetRows rows
154 * @default 0
155 */
156 sheetRows?: number;
157
158 /**
159 * If true, parse calculation chains
160 * @default false
161 */
162 bookDeps?: boolean;
163
164 /**
165 * If true, add raw files to book object
166 * @default false
167 */
168 bookFiles?: boolean;
169
170 /**
171 * If true, only parse enough to get book metadata
172 * @default false
173 */
174 bookProps?: boolean;
175
176 /**
177 * If true, only parse enough to get the sheet names
178 * @default false
179 */
180 bookSheets?: boolean;
181
182 /**
183 * If defined and file is encrypted, use password
184 * @default ''
185 */
186 password?: string;
187
188 /* If true, plaintext parsing will not parse values */
189 raw?: boolean;
190
191 dense?: boolean;
192 }
193
194 /** Options for write and writeFile */
195 export interface WritingOptions extends CommonOptions {
196 /** Output data encoding */
197 type?: 'base64' | 'binary' | 'buffer' | 'file' | 'array' | 'string';
198
199 /**
200 * Generate Shared String Table
201 * @default false
202 */
203 bookSST?: boolean;
204
205 /**
206 * File format of generated workbook
207 * @default 'xlsx'
208 */
209 bookType?: BookType;
210
211 /**
212 * Name of Worksheet (for single-sheet formats)
213 * @default ''
214 */
215 sheet?: string;
216
217 /**
218 * Use ZIP compression for ZIP-based formats
219 * @default false
220 */
221 compression?: boolean;
222
223 /** Override workbook properties on save */
224 Props?: Properties;
225 }
226
227 /** Workbook Object */
228 export interface WorkBook {
229 /**
230 * A dictionary of the worksheets in the workbook.
231 * Use SheetNames to reference these.
232 */
233 Sheets: { [sheet: string]: WorkSheet };
234
235 /** Ordered list of the sheet names in the workbook */
236 SheetNames: string[];
237
238 /**
239 * an object storing the standard properties. wb.Custprops stores custom properties.
240 * Since the XLS standard properties deviate from the XLSX standard, XLS parsing stores core properties in both places.
241 */
242 Props?: FullProperties;
243
244 Workbook?: WBProps;
245
246 vbaraw?: any;
247 }
248
249 export interface SheetProps {
250 /** Sheet Visibility (0=Visible 1=Hidden 2=VeryHidden) */
251 Hidden?: 0 | 1 | 2;
252
253 /** Name of Document Module in associated VBA Project */
254 CodeName?: string;
255 }
256
257 /** Defined Name Object */
258 export interface DefinedName {
259 /** Name */
260 Name: string;
261
262 /** Reference */
263 Ref: string;
264
265 /** Scope (undefined for workbook scope) */
266 Sheet?: number;
267
268 /** Name comment */
269 Comment?: string;
270 }
271
272 /** Workbook-Level Attributes */
273 export interface WBProps {
274 /** Sheet Properties */
275 Sheets?: SheetProps[];
276
277 /** Defined Names */
278 Names?: DefinedName[];
279
280 /** Workbook Views */
281 Views?: WBView[];
282
283 /** Other Workbook Properties */
284 WBProps?: WorkbookProperties;
285 }
286
287 /** Workbook View */
288 export interface WBView {
289 /** Right-to-left mode */
290 RTL?: boolean;
291 }
292
293 /** Other Workbook Properties */
294 export interface WorkbookProperties {
295 /** Worksheet Epoch (1904 if true, 1900 if false) */
296 date1904?: boolean;
297
298 /** Warn or strip personally identifying info on save */
299 filterPrivacy?: boolean;
300
301 /** Name of Document Module in associated VBA Project */
302 CodeName?: string;
303 }
304
305 /** Column Properties Object */
306 export interface ColInfo {
307 /* --- visibility --- */
308
309 /** if true, the column is hidden */
310 hidden?: boolean;
311
312 /* --- column width --- */
313
314 /** width in Excel's "Max Digit Width", width*256 is integral */
315 width?: number;
316
317 /** width in screen pixels */
318 wpx?: number;
319
320 /** width in "characters" */
321 wch?: number;
322
323 /** Excel's "Max Digit Width" unit, always integral */
324 MDW?: number;
325 }
326
327 /** Row Properties Object */
328 export interface RowInfo {
329 /* --- visibility --- */
330
331 /** if true, the column is hidden */
332 hidden?: boolean;
333
334 /* --- row height --- */
335
336 /** height in screen pixels */
337 hpx?: number;
338
339 /** height in points */
340 hpt?: number;
341
342 /** outline / group level */
343 level?: number;
344 }
345
346 /**
347 * Write sheet protection properties.
348 */
349 export interface ProtectInfo {
350 /**
351 * The password for formats that support password-protected sheets
352 * (XLSX/XLSB/XLS). The writer uses the XOR obfuscation method.
353 */
354 password?: string;
355 /**
356 * Select locked cells
357 * @default: true
358 */
359 selectLockedCells?: boolean;
360 /**
361 * Select unlocked cells
362 * @default: true
363 */
364 selectUnlockedCells?: boolean;
365 /**
366 * Format cells
367 * @default: false
368 */
369 formatCells?: boolean;
370 /**
371 * Format columns
372 * @default: false
373 */
374 formatColumns?: boolean;
375 /**
376 * Format rows
377 * @default: false
378 */
379 formatRows?: boolean;
380 /**
381 * Insert columns
382 * @default: false
383 */
384 insertColumns?: boolean;
385 /**
386 * Insert rows
387 * @default: false
388 */
389 insertRows?: boolean;
390 /**
391 * Insert hyperlinks
392 * @default: false
393 */
394 insertHyperlinks?: boolean;
395 /**
396 * Delete columns
397 * @default: false
398 */
399 deleteColumns?: boolean;
400 /**
401 * Delete rows
402 * @default: false
403 */
404 deleteRows?: boolean;
405 /**
406 * Sort
407 * @default: false
408 */
409 sort?: boolean;
410 /**
411 * Filter
412 * @default: false
413 */
414 autoFilter?: boolean;
415 /**
416 * Use PivotTable reports
417 * @default: false
418 */
419 pivotTables?: boolean;
420 /**
421 * Edit objects
422 * @default: true
423 */
424 objects?: boolean;
425 /**
426 * Edit scenarios
427 * @default: true
428 */
429 scenarios?: boolean;
430 }
431
432 /** Page Margins -- see Excel Page Setup .. Margins diagram for explanation */
433 export interface MarginInfo {
434 /** Left side margin (inches) */
435 left?: number;
436 /** Right side margin (inches) */
437 right?: number;
438 /** Top side margin (inches) */
439 top?: number;
440 /** Bottom side margin (inches) */
441 bottom?: number;
442 /** Header top margin (inches) */
443 header?: number;
444 /** Footer bottom height (inches) */
445 footer?: number;
446 }
447 export type SheetType = 'sheet' | 'chart';
448 export type SheetKeys = string | MarginInfo | SheetType;
449 /** General object representing a Sheet (worksheet or chartsheet) */
450 export interface Sheet {
451 /**
452 * Indexing with a cell address string maps to a cell object
453 * Special keys start with '!'
454 */
455 [cell: string]: CellObject | SheetKeys | any;
456
457 /** Sheet type */
458 '!type'?: SheetType;
459
460 /** Sheet Range */
461 '!ref'?: string;
462
463 /** Page Margins */
464 '!margins'?: MarginInfo;
465 }
466
467 /** AutoFilter properties */
468 export interface AutoFilterInfo {
469 /** Range of the AutoFilter table */
470 ref: string;
471 }
472 export type WSKeys = SheetKeys | ColInfo[] | RowInfo[] | Range[] | ProtectInfo | AutoFilterInfo;
473
474 /** Worksheet Object */
475 export interface WorkSheet extends Sheet {
476 /**
477 * Indexing with a cell address string maps to a cell object
478 * Special keys start with '!'
479 */
480 [cell: string]: CellObject | WSKeys | any;
481
482 /** Column Info */
483 '!cols'?: ColInfo[];
484
485 /** Row Info */
486 '!rows'?: RowInfo[];
487
488 /** Merge Ranges */
489 '!merges'?: Range[];
490
491 /** Worksheet Protection info */
492 '!protect'?: ProtectInfo;
493
494 /** AutoFilter info */
495 '!autofilter'?: AutoFilterInfo;
496 }
497
498 /**
499 * The Excel data type for a cell.
500 * b Boolean, n Number, e error, s String, d Date, z Stub
501 */
502 export type ExcelDataType = 'b' | 'n' | 'e' | 's' | 'd' | 'z';
503
504 /**
505 * Type of generated workbook
506 * @default 'xlsx'
507 */
508 export type BookType = 'xlsx' | 'xlsm' | 'xlsb' | 'xls' | 'xla' | 'biff8' | 'biff5' | 'biff2' | 'xlml' | 'ods' | 'fods' | 'csv' | 'txt' | 'sylk' | 'html' | 'dif' | 'rtf' | 'prn' | 'eth';
509
510 /** Comment element */
511 export interface Comment {
512 /** Author of the comment block */
513 a?: string;
514
515 /** Plaintext of the comment */
516 t: string;
517 }
518
519 /** Link object */
520 export interface Hyperlink {
521 /** Target of the link (HREF) */
522 Target: string;
523
524 /** Plaintext tooltip to display when mouse is over cell */
525 Tooltip?: string;
526 }
527
528 /** Worksheet Cell Object */
529 export interface CellObject {
530 /** The raw value of the cell. Can be omitted if a formula is specified */
531 v?: string | number | boolean | Date;
532
533 /** Formatted text (if applicable) */
534 w?: string;
535
536 /**
537 * The Excel Data Type of the cell.
538 * b Boolean, n Number, e Error, s String, d Date, z Empty
539 */
540 t: ExcelDataType;
541
542 /** Cell formula (if applicable) */
543 f?: string;
544
545 /** Range of enclosing array if formula is array formula (if applicable) */
546 F?: string;
547
548 /** Rich text encoding (if applicable) */
549 r?: any;
550
551 /** HTML rendering of the rich text (if applicable) */
552 h?: string;
553
554 /** Comments associated with the cell */
555 c?: Comment[];
556
557 /** Number format string associated with the cell (if requested) */
558 z?: NumberFormat;
559
560 /** Cell hyperlink object (.Target holds link, .tooltip is tooltip) */
561 l?: Hyperlink;
562
563 /** The style/theme of the cell (if applicable) */
564 s?: any;
565 }
566
567 /** Simple Cell Address */
568 export interface CellAddress {
569 /** Column number */
570 c: number;
571 /** Row number */
572 r: number;
573 }
574
575 /**
576 * Range object (representing ranges like "A1:B2")
577 */
578 export interface Range {
579 /** Starting cell */
580 s: CellAddress;
581 /** Ending cell */
582 e: CellAddress;
583 }
584
585 export interface Sheet2CSVOpts extends DateNFOption {
586 /** Field Separator ("delimiter") */
587 FS?: string;
588
589 /** Record Separator ("row separator") */
590 RS?: string;
591
592 /** Remove trailing field separators in each record */
593 strip?: boolean;
594
595 /** Include blank lines in the CSV output */
596 blankrows?: boolean;
597
598 /** Skip hidden rows and columns in the CSV output */
599 skipHidden?: boolean;
600 }
601
602 export interface OriginOption {
603 /** Top-Left cell for operation (CellAddress or A1 string or row) */
604 origin?: number | string | CellAddress;
605 }
606
607 export interface Sheet2HTMLOpts {
608 /** TABLE element id attribute */
609 id?: string;
610
611 /** Add contenteditable to every cell */
612 editable?: boolean;
613
614 /** Header HTML */
615 header?: string;
616
617 /** Footer HTML */
618 footer?: string;
619 }
620
621 export interface Sheet2JSONOpts extends DateNFOption {
622 /** Output format */
623 header?: "A"|number|string[];
624
625 /** Override worksheet range */
626 range?: any;
627
628 /** Include or omit blank lines in the output */
629 blankrows?: boolean;
630
631 /** Default value for null/undefined values */
632 defval?: any;
633
634 /** if true, return raw data; if false, return formatted text */
635 raw?: boolean;
636 }
637
638 export interface AOA2SheetOpts extends CommonOptions, DateNFOption {
639 /**
640 * Create cell objects for stub cells
641 * @default false
642 */
643 sheetStubs?: boolean;
644 }
645
646 export interface SheetAOAOpts extends AOA2SheetOpts, OriginOption {}
647
648 export interface JSON2SheetOpts extends CommonOptions, DateNFOption {
649 /** Use specified column order */
650 header?: string[];
651
652 /** Skip header row in generated sheet */
653 skipHeader?: boolean;
654 }
655
656 export interface SheetJSONOpts extends JSON2SheetOpts, OriginOption {}
657
658 export interface Table2SheetOpts extends CommonOptions, DateNFOption {
659 /* If true, plaintext parsing will not parse values */
660 raw?: boolean;
661
662 /**
663 * If >0, read the first sheetRows rows
664 * @default 0
665 */
666 sheetRows?: number;
667 }
668
669 /** General utilities */
670 export interface XLSX$Utils {
671 /* --- Import Functions --- */
672
673 /** Converts an array of arrays of JS data to a worksheet. */
674 aoa_to_sheet<T>(data: T[][], opts?: AOA2SheetOpts): WorkSheet;
675 aoa_to_sheet(data: any[][], opts?: AOA2SheetOpts): WorkSheet;
676
677 /** Converts an array of JS objects to a worksheet. */
678 json_to_sheet<T>(data: T[], opts?: JSON2SheetOpts): WorkSheet;
679 json_to_sheet(data: any[], opts?: JSON2SheetOpts): WorkSheet;
680
681 /** BROWSER ONLY! Converts a TABLE DOM element to a worksheet. */
682 table_to_sheet(data: any, opts?: Table2SheetOpts): WorkSheet;
683 table_to_book(data: any, opts?: Table2SheetOpts): WorkBook;
684
685 /* --- Export Functions --- */
686
687 /** Converts a worksheet object to an array of JSON objects */
688 sheet_to_json<T>(worksheet: WorkSheet, opts?: Sheet2JSONOpts): T[];
689 sheet_to_json(worksheet: WorkSheet, opts?: Sheet2JSONOpts): any[][];
690 sheet_to_json(worksheet: WorkSheet, opts?: Sheet2JSONOpts): any[];
691
692 /** Generates delimiter-separated-values output */
693 sheet_to_csv(worksheet: WorkSheet, options?: Sheet2CSVOpts): string;
694
695 /** Generates UTF16 Formatted Text */
696 sheet_to_txt(worksheet: WorkSheet, options?: Sheet2CSVOpts): string;
697
698 /** Generates HTML */
699 sheet_to_html(worksheet: WorkSheet, options?: Sheet2HTMLOpts): string;
700
701 /** Generates a list of the formulae (with value fallbacks) */
702 sheet_to_formulae(worksheet: WorkSheet): string[];
703
704 /** Generates DIF */
705 sheet_to_dif(worksheet: WorkSheet, options?: Sheet2HTMLOpts): string;
706
707 /** Generates SYLK (Symbolic Link) */
708 sheet_to_slk(worksheet: WorkSheet, options?: Sheet2HTMLOpts): string;
709
710 /** Generates ETH */
711 sheet_to_eth(worksheet: WorkSheet, options?: Sheet2HTMLOpts): string;
712
713 /* --- Cell Address Utilities --- */
714
715 /** Converts 0-indexed cell address to A1 form */
716 encode_cell(cell: CellAddress): string;
717
718 /** Converts 0-indexed row to A1 form */
719 encode_row(row: number): string;
720
721 /** Converts 0-indexed column to A1 form */
722 encode_col(col: number): string;
723
724 /** Converts 0-indexed range to A1 form */
725 encode_range(s: CellAddress, e: CellAddress): string;
726 encode_range(r: Range): string;
727
728 /** Converts A1 cell address to 0-indexed form */
729 decode_cell(address: string): CellAddress;
730
731 /** Converts A1 row to 0-indexed form */
732 decode_row(row: string): number;
733
734 /** Converts A1 column to 0-indexed form */
735 decode_col(col: string): number;
736
737 /** Converts A1 range to 0-indexed form */
738 decode_range(range: string): Range;
739
740 /** Format cell */
741 format_cell(cell: CellObject, v?: any, opts?: any): string;
742
743 /* --- General Utilities --- */
744
745 /** Creates a new workbook */
746 book_new(): WorkBook;
747
748 /** Append a worksheet to a workbook */
749 book_append_sheet(workbook: WorkBook, worksheet: WorkSheet, name?: string): void;
750
751 /** Set sheet visibility (visible/hidden/very hidden) */
752 book_set_sheet_visibility(workbook: WorkBook, sheet: number|string, visibility: number): void;
753
754 /** Set number format for a cell */
755 cell_set_number_format(cell: CellObject, fmt: string|number): CellObject;
756
757 /** Set hyperlink for a cell */
758 cell_set_hyperlink(cell: CellObject, target: string, tooltip?: string): CellObject;
759
760 /** Set internal link for a cell */
761 cell_set_internal_link(cell: CellObject, target: string, tooltip?: string): CellObject;
762
763 /** Add comment to a cell */
764 cell_add_comment(cell: CellObject, text: string, author?: string): void;
765
766 /** Assign an Array Formula to a range */
767 sheet_set_array_formula(ws: WorkSheet, range: Range|string, formula: string): WorkSheet;
768
769 /** Add an array of arrays of JS data to a worksheet */
770 sheet_add_aoa<T>(ws: WorkSheet, data: T[][], opts?: SheetAOAOpts): WorkSheet;
771 sheet_add_aoa(ws: WorkSheet, data: any[][], opts?: SheetAOAOpts): WorkSheet;
772
773 /** Add an array of JS objects to a worksheet */
774 sheet_add_json(ws: WorkSheet, data: any[], opts?: SheetJSONOpts): WorkSheet;
775 sheet_add_json<T>(ws: WorkSheet, data: T[], opts?: SheetJSONOpts): WorkSheet;
776
777
778 consts: XLSX$Consts;
779 }
780
781 export interface XLSX$Consts {
782 /* --- Sheet Visibility --- */
783
784 /** Visibility: Visible */
785 SHEET_VISIBLE: 0;
786
787 /** Visibility: Hidden */
788 SHEET_HIDDEN: 1;
789
790 /** Visibility: Very Hidden */
791 SHEET_VERYHIDDEN: 2;
792 }
793
794 /** NODE ONLY! these return Readable Streams */
795 export interface StreamUtils {
796 /** CSV output stream, generate one line at a time */
797 to_csv(sheet: WorkSheet, opts?: Sheet2CSVOpts): any;
798 /** HTML output stream, generate one line at a time */
799 to_html(sheet: WorkSheet, opts?: Sheet2HTMLOpts): any;
800 }
801
802}
\No newline at end of file