From 3a496db46883a4890fe717388e8db6d4f8b245ef Mon Sep 17 00:00:00 2001 From: Josh Petersen Date: Wed, 3 Jun 2015 09:34:42 -0400 Subject: [PATCH 01/34] added definitions and tests for project xlsx https://github.com/SheetJS/js-xlsx --- xlsx-tests.ts | 26 ++++++++++ xlsx.d.ts | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 xlsx-tests.ts create mode 100644 xlsx.d.ts diff --git a/xlsx-tests.ts b/xlsx-tests.ts new file mode 100644 index 0000000..7a40546 --- /dev/null +++ b/xlsx-tests.ts @@ -0,0 +1,26 @@ +/// +import xlsx = require('xlsx'); + +var options:xlsx.IParsingOptions = { + cellDates:true +}; + +var workbook = xlsx.readFile('test.xlsx', options); +var otherworkbook = xlsx.readFile('test.xlsx', {type: 'file'}); + +console.log(workbook.Props.Author); + +var firstsheet:string = workbook.SheetNames[0]; + +var firstworksheet = workbook.Sheets[firstsheet]; + +console.log(firstworksheet["A1"]); + +interface tester { + name:string; + age: number; +} + +var jsonvalues:tester[] = xlsx.utils.sheet_to_json(firstworksheet); +var csv = xlsx.utils.sheet_to_csv(firstworksheet); +var formulae = xlsx.utils.sheet_to_formulae(firstworksheet); diff --git a/xlsx.d.ts b/xlsx.d.ts new file mode 100644 index 0000000..16df800 --- /dev/null +++ b/xlsx.d.ts @@ -0,0 +1,136 @@ +// Type definitions for xlsx +// Project: https://github.com/SheetJS/js-xlsx +// Definitions by: themauveavenger +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'xlsx' { + + export function readFile(filename:string, opts?:IParsingOptions):IWorkBook; + export function read(data:any, opts?:IParsingOptions):IWorkBook; + export 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 { + cellFormula?:boolean; + cellHTML?:boolean; + cellNF?:boolean; + cellStyles?:boolean; + cellDates?:boolean; + sheetStubs?:boolean; + sheetRows?:number; + bookDeps?:boolean; + bookFiles?:boolean; + bookProps?:boolean; + bookSheets?:boolean; + bookVBA?:boolean; + password?:string; + + /** + * Possible options: 'binary', 'base64', 'buffer', 'file' + */ + type?:string; + } + + 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 { + [cell:string]:IWorkSheetCell; + } + + export interface IWorkSheetCell { + /** + * The Excel Data Type of the cell. + * b Boolean, n Number, e error, s String, d Date + */ + t: string; + + /** + * The raw value of the cell. + */ + v: string; + + /** + * rich text encoding (if applicable) + */ + r?: string; + + /** + * HTML rendering of the rich text (if applicable) + */ + h?: string; + + /** + * formatted text (if applicable) + */ + w?: string; + + /** + * cell formula (if applicable) + */ + f?: string; + + /** + * comments associated with the cell ** + */ + c?: string; + + /** + * number format string associated with the cell (if requested) + */ + z?: string; + + /** + * cell hyperlink object (.Target holds link, .tooltip is tooltip) + */ + l?: string; + + /** + * the style/theme of the cell (if applicable) + */ + s?: string; + } + + export interface IUtils { + sheet_to_json(worksheet:IWorkSheet|IWorkBook):T[]; + sheet_to_csv(worksheet:IWorkSheet):any; + sheet_to_formulae(worksheet:IWorkSheet):any; + } + +} From a345c332ac179885be239b8d6e05475570353b9e Mon Sep 17 00:00:00 2001 From: Josh Petersen Date: Wed, 3 Jun 2015 14:25:05 -0400 Subject: [PATCH 02/34] minor fix. sheet_to_json only accepts worksheet as a parameter. --- xlsx.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xlsx.d.ts b/xlsx.d.ts index 16df800..cdc7534 100644 --- a/xlsx.d.ts +++ b/xlsx.d.ts @@ -128,7 +128,7 @@ declare module 'xlsx' { } export interface IUtils { - sheet_to_json(worksheet:IWorkSheet|IWorkBook):T[]; + sheet_to_json(worksheet:IWorkSheet):T[]; sheet_to_csv(worksheet:IWorkSheet):any; sheet_to_formulae(worksheet:IWorkSheet):any; } From a102a3adb14162c38f5fb0a3356f1f9c66c9c2d8 Mon Sep 17 00:00:00 2001 From: vvakame Date: Thu, 17 Mar 2016 00:31:58 +0900 Subject: [PATCH 03/34] replace https://github.com/borisyankov/DefinitelyTyped to https://github.com/DefinitelyTyped/DefinitelyTyped --- xlsx.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xlsx.d.ts b/xlsx.d.ts index cdc7534..b761387 100644 --- a/xlsx.d.ts +++ b/xlsx.d.ts @@ -1,7 +1,7 @@ // Type definitions for xlsx // Project: https://github.com/SheetJS/js-xlsx // Definitions by: themauveavenger -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module 'xlsx' { From 96df2958abbf60030a47c3fcacadda54d2d6d9e3 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Fri, 22 Apr 2016 14:12:45 -0700 Subject: [PATCH 04/34] Unwrap all lone ambient external modules --- xlsx.d.ts | 244 +++++++++++++++++++++++++++--------------------------- 1 file changed, 121 insertions(+), 123 deletions(-) diff --git a/xlsx.d.ts b/xlsx.d.ts index b761387..e53c436 100644 --- a/xlsx.d.ts +++ b/xlsx.d.ts @@ -3,134 +3,132 @@ // Definitions by: themauveavenger // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module 'xlsx' { - export function readFile(filename:string, opts?:IParsingOptions):IWorkBook; - export function read(data:any, opts?:IParsingOptions):IWorkBook; - export 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[]; - } +declare export function readFile(filename: string, opts?: IParsingOptions): IWorkBook; +declare export function read(data: any, opts?: IParsingOptions): IWorkBook; +declare export var utils: IUtils; - export interface IParsingOptions { - cellFormula?:boolean; - cellHTML?:boolean; - cellNF?:boolean; - cellStyles?:boolean; - cellDates?:boolean; - sheetStubs?:boolean; - sheetRows?:number; - bookDeps?:boolean; - bookFiles?:boolean; - bookProps?:boolean; - bookSheets?:boolean; - bookVBA?:boolean; - password?:string; +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[]; +} - /** - * Possible options: 'binary', 'base64', 'buffer', 'file' - */ - type?:string; - } - - 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; - } +export interface IParsingOptions { + cellFormula?: boolean; + cellHTML?: boolean; + cellNF?: boolean; + cellStyles?: boolean; + cellDates?: boolean; + sheetStubs?: boolean; + sheetRows?: number; + bookDeps?: boolean; + bookFiles?: boolean; + bookProps?: boolean; + bookSheets?: boolean; + bookVBA?: boolean; + password?: string; /** - * object representing the worksheet + * Possible options: 'binary', 'base64', 'buffer', 'file' */ - export interface IWorkSheet { - [cell:string]:IWorkSheetCell; - } - - export interface IWorkSheetCell { - /** - * The Excel Data Type of the cell. - * b Boolean, n Number, e error, s String, d Date - */ - t: string; - - /** - * The raw value of the cell. - */ - v: string; - - /** - * rich text encoding (if applicable) - */ - r?: string; - - /** - * HTML rendering of the rich text (if applicable) - */ - h?: string; - - /** - * formatted text (if applicable) - */ - w?: string; - - /** - * cell formula (if applicable) - */ - f?: string; - - /** - * comments associated with the cell ** - */ - c?: string; - - /** - * number format string associated with the cell (if requested) - */ - z?: string; - - /** - * cell hyperlink object (.Target holds link, .tooltip is tooltip) - */ - l?: string; - - /** - * the style/theme of the cell (if applicable) - */ - s?: string; - } - - export interface IUtils { - sheet_to_json(worksheet:IWorkSheet):T[]; - sheet_to_csv(worksheet:IWorkSheet):any; - sheet_to_formulae(worksheet:IWorkSheet):any; - } - + type?: string; +} + +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 { + [cell: string]: IWorkSheetCell; +} + +export interface IWorkSheetCell { + /** + * The Excel Data Type of the cell. + * b Boolean, n Number, e error, s String, d Date + */ + t: string; + + /** + * The raw value of the cell. + */ + v: string; + + /** + * rich text encoding (if applicable) + */ + r?: string; + + /** + * HTML rendering of the rich text (if applicable) + */ + h?: string; + + /** + * formatted text (if applicable) + */ + w?: string; + + /** + * cell formula (if applicable) + */ + f?: string; + + /** + * comments associated with the cell ** + */ + c?: string; + + /** + * number format string associated with the cell (if requested) + */ + z?: string; + + /** + * cell hyperlink object (.Target holds link, .tooltip is tooltip) + */ + l?: string; + + /** + * the style/theme of the cell (if applicable) + */ + s?: string; +} + +export interface IUtils { + sheet_to_json(worksheet: IWorkSheet): T[]; + sheet_to_csv(worksheet: IWorkSheet): any; + sheet_to_formulae(worksheet: IWorkSheet): any; } From 14d28e6a6a3ce913a7f4020f8fa7ab427d4b14ef Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 25 Apr 2016 13:02:25 -0700 Subject: [PATCH 05/34] Fix angularjs/angular; 'export declare'/'declare export' --- xlsx.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xlsx.d.ts b/xlsx.d.ts index e53c436..61e7346 100644 --- a/xlsx.d.ts +++ b/xlsx.d.ts @@ -5,9 +5,9 @@ -declare export function readFile(filename: string, opts?: IParsingOptions): IWorkBook; -declare export function read(data: any, opts?: IParsingOptions): IWorkBook; -declare export var utils: IUtils; +export declare function readFile(filename: string, opts?: IParsingOptions): IWorkBook; +export declare function read(data: any, opts?: IParsingOptions): IWorkBook; +export declare var utils: IUtils; export interface IProperties { LastAuthor?: string From 2b42c39913915664129b5c2487b5d2d3464bee39 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 27 Apr 2016 20:40:21 -0700 Subject: [PATCH 06/34] Merge remote-tracking branch 'upstream/master' into types2.0 Add tsconfig files everywhere # Conflicts: # azure-mobile-services-client/AzureMobileServicesClient.d.ts # bookshelf/bookshelf.d.ts # hapi/hapi.d.ts # helmet/helmet.d.ts # mongodb/mongodb.d.ts # nock/nock.d.ts # react-bootstrap/react-bootstrap.d.ts # react-helmet/react-helmet.d.ts # restify/restify.d.ts # sequelize/sequelize.d.ts --- tsconfig.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..ac08134 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2015", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../" + } +} \ No newline at end of file From c73e83fab59ce073268b03edc5941cbc774861d4 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 27 Apr 2016 21:30:22 -0700 Subject: [PATCH 07/34] Rename external modules to index.d.ts --- xlsx.d.ts => index.d.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename xlsx.d.ts => index.d.ts (100%) diff --git a/xlsx.d.ts b/index.d.ts similarity index 100% rename from xlsx.d.ts rename to index.d.ts From 82537cbca490101dfc75591ce45d71e264f9d7df Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 27 Apr 2016 21:53:46 -0700 Subject: [PATCH 08/34] Remove obsolesced reference comments --- xlsx-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xlsx-tests.ts b/xlsx-tests.ts index 7a40546..1817ec8 100644 --- a/xlsx-tests.ts +++ b/xlsx-tests.ts @@ -1,4 +1,4 @@ -/// + import xlsx = require('xlsx'); var options:xlsx.IParsingOptions = { From 7e32abdb265888eec759cd962ee40dd304d480b1 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 4 May 2016 14:14:39 -0700 Subject: [PATCH 09/34] Add tsconfig.json files --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index ac08134..83c2c46 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "module": "commonjs", - "target": "es2015", + "target": "es6", "noImplicitAny": true, "strictNullChecks": true, "baseUrl": "../" From c265359abd3cb2cdceb164672f4c733d18601717 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 4 May 2016 15:08:38 -0700 Subject: [PATCH 10/34] Turn off strict null checks --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 83c2c46..effc71d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "module": "commonjs", "target": "es6", "noImplicitAny": true, - "strictNullChecks": true, + "strictNullChecks": false, "baseUrl": "../" } } \ No newline at end of file From 20a85521992096720ff9647a844c1dd3a65a214f Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 9 May 2016 13:52:25 -0700 Subject: [PATCH 11/34] Add typesRoot to all config files --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index effc71d..cca0e65 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "target": "es6", "noImplicitAny": true, "strictNullChecks": false, - "baseUrl": "../" + "baseUrl": "../", + "typesRoot": "../" } } \ No newline at end of file From 5ceec62f2ac047082616c7232ac504a19e4c01f5 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 9 May 2016 17:29:10 -0700 Subject: [PATCH 12/34] Rename all entry points to index.d.ts and explicitify all file lists --- tsconfig.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index cca0e65..224d101 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,5 +6,9 @@ "strictNullChecks": false, "baseUrl": "../", "typesRoot": "../" - } + }, + "files": [ + "index.d.ts", + "xlsx-tests.ts" + ] } \ No newline at end of file From 4039f599e718bc4eb9a25fe28f6bce9011d1b62e Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 9 May 2016 18:06:27 -0700 Subject: [PATCH 13/34] Change relative reference paths to types references. Errors incoming... --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 224d101..948d458 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "noImplicitAny": true, "strictNullChecks": false, "baseUrl": "../", - "typesRoot": "../" + "typesSearchPaths": ["../"] }, "files": [ "index.d.ts", From 22c1dca6e0beee54be0b4423f2d6ff94c612e607 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 10 May 2016 12:24:49 -0700 Subject: [PATCH 14/34] Add noEmit to all config files --- tsconfig.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 948d458..fef4d9c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,10 @@ "noImplicitAny": true, "strictNullChecks": false, "baseUrl": "../", - "typesSearchPaths": ["../"] + "typesSearchPaths": [ + "../" + ], + "noEmit": true }, "files": [ "index.d.ts", From bc12a8d2b377f81f6228fdd137d40432461dbaf3 Mon Sep 17 00:00:00 2001 From: Raghav Katyal Date: Thu, 30 Jun 2016 15:14:49 -0700 Subject: [PATCH 15/34] Turning on consistent casing flag and fixing failures --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index fef4d9c..66fb879 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,8 @@ "typesSearchPaths": [ "../" ], - "noEmit": true + "noEmit": true, + "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", From d8a13d0dc2488545f2461f9d2ff72b9e76979397 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Tue, 12 Jul 2016 13:54:56 -0700 Subject: [PATCH 16/34] Fix tsconfig files for new option name / behavior. Also fixes some inconsistent whitespace. --- tsconfig.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 66fb879..3204b37 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,11 +5,12 @@ "noImplicitAny": true, "strictNullChecks": false, "baseUrl": "../", - "typesSearchPaths": [ + "typeRoots": [ "../" ], + "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true }, "files": [ "index.d.ts", From 5e2768ac846ccdd750f59b3bc88acaa3920b9ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C4=81rlis=20Ga=C5=86=C4=A3is?= Date: Thu, 11 Aug 2016 14:10:56 +0300 Subject: [PATCH 17/34] Added `opts` parameter to sheet_to_json method. --- xlsx.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xlsx.d.ts b/xlsx.d.ts index b761387..766be99 100644 --- a/xlsx.d.ts +++ b/xlsx.d.ts @@ -128,7 +128,11 @@ declare module 'xlsx' { } export interface IUtils { - sheet_to_json(worksheet:IWorkSheet):T[]; + sheet_to_json(worksheet:IWorkSheet, opts?: { + raw?: boolean; + range?: any; + header?: "A"|number|string[]; + }):T[]; sheet_to_csv(worksheet:IWorkSheet):any; sheet_to_formulae(worksheet:IWorkSheet):any; } From 09c3f9db84422bc9919d9656ee49fd72c330b54c Mon Sep 17 00:00:00 2001 From: Hagai Cohen Date: Thu, 11 Aug 2016 19:20:48 +0300 Subject: [PATCH 18/34] Fixed XLSX typings --- xlsx.d.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xlsx.d.ts b/xlsx.d.ts index 766be99..68f89b5 100644 --- a/xlsx.d.ts +++ b/xlsx.d.ts @@ -7,6 +7,7 @@ declare module 'xlsx' { export function readFile(filename:string, opts?:IParsingOptions):IWorkBook; export function read(data:any, opts?:IParsingOptions):IWorkBook; + export function write(data:any, opts?:IParsingOptions): any; export var utils:IUtils; export interface IProperties { @@ -41,6 +42,7 @@ declare module 'xlsx' { bookSheets?:boolean; bookVBA?:boolean; password?:string; + bookType?:string; /** * Possible options: 'binary', 'base64', 'buffer', 'file' @@ -127,14 +129,21 @@ declare module 'xlsx' { s?: string; } + export interface ICell { + c: number; + r: number; + } + export interface IUtils { sheet_to_json(worksheet:IWorkSheet, opts?: { raw?: boolean; range?: any; header?: "A"|number|string[]; }):T[]; - sheet_to_csv(worksheet:IWorkSheet):any; - sheet_to_formulae(worksheet:IWorkSheet):any; + sheet_to_csv(worksheet: IWorkSheet):any; + sheet_to_formulae(worksheet: IWorkSheet):any; + encode_cell(cell: ICell): any; + encode_range(s: ICell, e: ICell): any; } } From 4de60e9ca9b5038533625d10425aa0ab2504f2cb Mon Sep 17 00:00:00 2001 From: Hagai Cohen Date: Thu, 11 Aug 2016 23:18:32 +0300 Subject: [PATCH 19/34] Aligned xlsx types to master xlsx/xlsx.d.ts --- index.d.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 61e7346..6308f66 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,10 +3,9 @@ // Definitions by: themauveavenger // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - - export declare function readFile(filename: string, opts?: IParsingOptions): IWorkBook; export declare function read(data: any, opts?: IParsingOptions): IWorkBook; +export declare function write(data: any, opts?: IParsingOptions): any; export declare var utils: IUtils; export interface IProperties { @@ -41,6 +40,7 @@ export interface IParsingOptions { bookSheets?: boolean; bookVBA?: boolean; password?: string; + bookType?: string; /** * Possible options: 'binary', 'base64', 'buffer', 'file' @@ -127,8 +127,19 @@ export interface IWorkSheetCell { s?: string; } +export interface ICell { + c: number; + r: number; +} + export interface IUtils { - sheet_to_json(worksheet: IWorkSheet): T[]; + sheet_to_json(worksheet: IWorkSheet, opts?: { + raw?: boolean; + range?: any; + header?: "A"|number|string[]; + }): T[]; sheet_to_csv(worksheet: IWorkSheet): any; sheet_to_formulae(worksheet: IWorkSheet): any; + encode_cell(cell: ICell): any; + encode_range(s: ICell, e: ICell): any; } From 7c89b6e9b1e251bb8048cf5ade1dcde53d65177e Mon Sep 17 00:00:00 2001 From: groetzi Date: Mon, 14 Nov 2016 17:50:08 -0600 Subject: [PATCH 20/34] Update xlsx.d.ts added signatures for decode_[cell|range] --- xlsx.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xlsx.d.ts b/xlsx.d.ts index 68f89b5..6f29ac2 100644 --- a/xlsx.d.ts +++ b/xlsx.d.ts @@ -134,6 +134,11 @@ declare module 'xlsx' { r: number; } + export interface IRange { + s: ICell; + e: ICell; + } + export interface IUtils { sheet_to_json(worksheet:IWorkSheet, opts?: { raw?: boolean; @@ -144,6 +149,8 @@ declare module 'xlsx' { sheet_to_formulae(worksheet: IWorkSheet):any; encode_cell(cell: ICell): any; encode_range(s: ICell, e: ICell): any; + decode_cell(address: string): ICell; + decode_range(range: string): IRange; } } From 01a3806eb5f1c7b64a3e211764def4d415cc3d23 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 19 Dec 2016 14:11:46 -0800 Subject: [PATCH 21/34] Add "noImplicitThis" to all tsconfig.json (#13446) * Add "noImplicitThis" to all tsconfig.json * Use `"noImplicitThis": false` on packages with broken tests. --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index 3204b37..6d69f32 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "module": "commonjs", "target": "es6", "noImplicitAny": true, + "noImplicitThis": true, "strictNullChecks": false, "baseUrl": "../", "typeRoots": [ From 276b1ae79fd3906003e61439f637a0d63559d5e9 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 18 Jan 2017 07:51:51 -0800 Subject: [PATCH 22/34] Use "lib" in tsconfigs instead of "target". (#13968) * Use "lib" in tsconfigs instead of "target". Only add "dom" to libraries that need it. This is determined by a script, so many libraries that have "dom" maybe should not. * Update new-package and readme * Add back "target" where necessary --- tsconfig.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 6d69f32..c202db1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,10 @@ { "compilerOptions": { "module": "commonjs", - "target": "es6", + "lib": [ + "es6", + "dom" + ], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": false, From a234ec5915587570a8c2533ca79645897d3cae24 Mon Sep 17 00:00:00 2001 From: rinzeb Date: Tue, 7 Feb 2017 13:21:31 +0100 Subject: [PATCH 23/34] Update xlsx typings Add optional 'options' parameter to function sheet_to_csv. (https://github.com/SheetJS/js-xlsx/blob/53f7f6d9446ccd680c9b13992d6dcdccde49a8f6/bits/90_utils.js#L132) --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 3c78abb..4e4eb06 100644 --- a/index.d.ts +++ b/index.d.ts @@ -143,7 +143,7 @@ export interface IUtils { range?: any; header?: "A"|number|string[]; }):T[]; - sheet_to_csv(worksheet: IWorkSheet):any; + sheet_to_csv(worksheet: IWorkSheet, options?: { FS: string, RS: string }): string; sheet_to_formulae(worksheet: IWorkSheet):any; encode_cell(cell: ICell): any; encode_range(s: ICell, e: ICell): any; From aa86eef7fcfe787f5bf16589be75390c9fc6328f Mon Sep 17 00:00:00 2001 From: DMan577 Date: Sun, 12 Mar 2017 09:21:11 +0200 Subject: [PATCH 24/34] Update index.d.ts --- index.d.ts | 216 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 174 insertions(+), 42 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4e4eb06..6af7911 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,9 +3,15 @@ // Definitions by: themauveavenger // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/** Attempts to read filename and parse */ export declare function readFile(filename: string, opts?: IParsingOptions): IWorkBook; +/** Attempts to parse data */ export declare function read(data: any, opts?: IParsingOptions): IWorkBook; -export declare function write(data: any, opts?: IParsingOptions): any; +/** 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 { @@ -27,25 +33,125 @@ export interface IProperties { } export interface IParsingOptions { - cellFormula?: boolean; - cellHTML?: boolean; - cellNF?: boolean; - cellStyles?: boolean; - cellDates?: boolean; - sheetStubs?: boolean; - sheetRows?: number; - bookDeps?: boolean; - bookFiles?: boolean; - bookProps?: boolean; - bookSheets?: boolean; - bookVBA?: boolean; - password?: string; - bookType?: string; + /** + * Input data encoding + */ + type?: 'base64' | 'binary' | 'buffer' | 'array' | 'file'; /** - * Possible options: 'binary', 'base64', 'buffer', 'file' + * Save formulae to the .f field + * @default true */ - type?: string; + cellFormula?: boolean; + + /** + * Parse rich text and save HTML to the .h field + * @default true + */ + cellHTML?: boolean; + + /** + * Save number format string to the .z field + * @default false + */ + cellNF?: boolean; + + /** + * Save style/theme info to the .s field + * @default false + */ + cellStyles?: boolean; + + /** + * Store dates as type d (default is n) + * @default false + */ + cellDates?: boolean; + + /** + * Create cell objects for stub cells + * @default false + */ + sheetStubs?: boolean; + + /** + * If >0, read the first sheetRows rows + * @default 0 + */ + sheetRows?: number; + + /** + * If true, parse calculation chains + * @default false + */ + bookDeps?: boolean; + + /** + * If true, add raw files to book object + * @default false + */ + bookFiles?: boolean; + + /** + * If true, only parse enough to get book metadata + * @default false + */ + bookProps?: boolean; + + /** + * If true, only parse enough to get the sheet names + * @default false + */ + bookSheets?: boolean; + + /** + * If true, expose vbaProject.bin to vbaraw field + * @default false + */ + bookVBA?: boolean; + + /** + * If defined and file is encrypted, use password + * @default '' + */ + password?: string; +} + +export interface IWritingOptions { + /** + * Output data encoding + */ + 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 { @@ -75,19 +181,34 @@ export interface IWorkSheet { } export interface IWorkSheetCell { - /** - * The Excel Data Type of the cell. - * b Boolean, n Number, e error, s String, d Date - */ - t: string; - /** * The raw value of the cell. */ - v: string; + v: string | number | boolean | Date; /** - * rich text encoding (if applicable) + * Formatted text (if applicable) + */ + w?: string; + + /** + * 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) + */ + f?: string; + + /** + * Range of enclosing array if formula is array formula (if applicable) + */ + F?: string; + + /** + * Rich text encoding (if applicable) */ r?: string; @@ -97,56 +218,67 @@ export interface IWorkSheetCell { h?: string; /** - * formatted text (if applicable) - */ - w?: string; - - /** - * cell formula (if applicable) - */ - f?: string; - - /** - * comments associated with the cell ** + * Comments associated with the cell ** */ c?: string; /** - * number format string associated with the cell (if requested) + * Number format string associated with the cell (if requested) */ z?: string; /** - * cell hyperlink object (.Target holds link, .tooltip is tooltip) + * Cell hyperlink object (.Target holds link, .tooltip is tooltip) */ - l?: string; + l?: string | Object; /** - * the style/theme of the cell (if applicable) + * The style/theme of the cell (if applicable) */ s?: string; } export interface ICell { + /** Column number */ c: number; + /** Row number */ r: number; } export interface IRange { + /** Starting cell */ s: ICell; + /** Ending cell */ e: ICell; } export interface IUtils { + /** Converts a worksheet object to an array of JSON objects */ sheet_to_json(worksheet:IWorkSheet, opts?: { raw?: boolean; range?: any; header?: "A"|number|string[]; }):T[]; + /** Generates delimiter-separated-values output */ sheet_to_csv(worksheet: IWorkSheet, options?: { FS: string, RS: string }): string; + /** Generates a list of the formulae (with value fallbacks) */ sheet_to_formulae(worksheet: IWorkSheet):any; - encode_cell(cell: ICell): any; - encode_range(s: ICell, e: ICell): any; + + /** 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; + /** 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; } From 0537ed70aaa7439f87d9bf6c592ee7980ce35506 Mon Sep 17 00:00:00 2001 From: DMan577 Date: Tue, 14 Mar 2017 20:02:19 +0200 Subject: [PATCH 25/34] Update index.d.ts --- index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6af7911..0e05c86 100644 --- a/index.d.ts +++ b/index.d.ts @@ -177,7 +177,7 @@ export interface IWorkBook { * object representing the worksheet */ export interface IWorkSheet { - [cell: string]: IWorkSheetCell; + [cell: string]: IWorkSheetCell | any; } export interface IWorkSheetCell { @@ -230,12 +230,12 @@ export interface IWorkSheetCell { /** * Cell hyperlink object (.Target holds link, .tooltip is tooltip) */ - l?: string | Object; + l?: Object; /** * The style/theme of the cell (if applicable) */ - s?: string; + s?: Object; } export interface ICell { From a5b8313ff41a3e97220d85cec3f6099ccf6e4501 Mon Sep 17 00:00:00 2001 From: Tim Burnell Date: Fri, 14 Apr 2017 14:16:23 -0500 Subject: [PATCH 26/34] add aoa_to_sheet because it was missing below are still missing, but i require aoa only. split_cell: format_cell get_formulae make_csv make_json make_formulae table_to_sheet table_to_book sheet_to_row_object_array --- index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.d.ts b/index.d.ts index 0e05c86..4b745a9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -253,6 +253,8 @@ export interface IRange { } export interface IUtils { + /** converts an array of arrays of JS data to a worksheet. */ + aoa_to_sheet(data:Array, opts?:any); /** Converts a worksheet object to an array of JSON objects */ sheet_to_json(worksheet:IWorkSheet, opts?: { raw?: boolean; From 8b9a008159513b51f78fa8de70a7929636e9d2d8 Mon Sep 17 00:00:00 2001 From: Tim Burnell Date: Fri, 14 Apr 2017 15:37:22 -0500 Subject: [PATCH 27/34] fix formatting and types --- index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 4b745a9..9b1b634 100644 --- a/index.d.ts +++ b/index.d.ts @@ -254,7 +254,8 @@ export interface IRange { export interface IUtils { /** converts an array of arrays of JS data to a worksheet. */ - aoa_to_sheet(data:Array, opts?:any); + aoa_to_sheet(data: , opts?:any): IWorkSheet; + /** Converts a worksheet object to an array of JSON objects */ sheet_to_json(worksheet:IWorkSheet, opts?: { raw?: boolean; From d0a59ae28356a1a99b5db87db7f984aa5a177437 Mon Sep 17 00:00:00 2001 From: Tim Burnell Date: Fri, 14 Apr 2017 15:49:38 -0500 Subject: [PATCH 28/34] fix error --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 9b1b634..3f3e45f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -254,7 +254,7 @@ export interface IRange { export interface IUtils { /** converts an array of arrays of JS data to a worksheet. */ - aoa_to_sheet(data: , opts?:any): IWorkSheet; + aoa_to_sheet(data: T[], opts?:any): IWorkSheet; /** Converts a worksheet object to an array of JSON objects */ sheet_to_json(worksheet:IWorkSheet, opts?: { From 29ed597df6464f760e3e2bccbcbe78a617ff6452 Mon Sep 17 00:00:00 2001 From: Wolfgang Faust Date: Fri, 12 May 2017 17:46:24 -0400 Subject: [PATCH 29/34] xlsx: Add properties of IWorkSheet. --- index.d.ts | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3f3e45f..dec0b13 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for xlsx // Project: https://github.com/SheetJS/js-xlsx -// Definitions by: themauveavenger +// Definitions by: themauveavenger , Wolfgang Faust // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /** Attempts to read filename and parse */ @@ -173,11 +173,154 @@ export interface IWorkBook { Props: IProperties; } +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, + }; +} + /** * object representing the worksheet */ -export interface IWorkSheet { +export interface IWorkSheet extends ISheet { [cell: string]: IWorkSheetCell | any; + '!cols'?: IColInfo[]; + '!rows'?: IRowInfo[]; + '!merges'?: IRange[]; + '!protect'?: IProtectInfo; + '!autofilter'?: {ref: string}; } export interface IWorkSheetCell { From bf73d629030063ebf89cdc4cc0abd437039fbd84 Mon Sep 17 00:00:00 2001 From: Wolfgang Faust Date: Fri, 12 May 2017 17:46:31 -0400 Subject: [PATCH 30/34] xlsx: Add new ExcelDataType type. This allows variables to be declared as this type so an error will be raised if an incorrect value is used. --- index.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index dec0b13..57a93ed 100644 --- a/index.d.ts +++ b/index.d.ts @@ -323,6 +323,12 @@ export interface IWorkSheet extends ISheet { '!autofilter'?: {ref: string}; } +/** +* 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'; + export interface IWorkSheetCell { /** * The raw value of the cell. @@ -338,7 +344,7 @@ export interface IWorkSheetCell { * The Excel Data Type of the cell. * b Boolean, n Number, e error, s String, d Date */ - t: 'b' | 'n' | 'e' | 's' | 'd'; + t: ExcelDataType; /** * Cell formula (if applicable) From 0fb38af783d234aa056e77233e3543c1726b7acf Mon Sep 17 00:00:00 2001 From: Wolfgang Faust Date: Fri, 12 May 2017 17:46:39 -0400 Subject: [PATCH 31/34] xlsx: Fix whitespace lints. --- index.d.ts | 20 ++++++++++---------- tslint.json | 1 + xlsx-tests.ts | 11 +++++------ 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 tslint.json diff --git a/index.d.ts b/index.d.ts index 57a93ed..4fc599d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -324,9 +324,9 @@ export interface IWorkSheet extends ISheet { } /** -* The Excel data type for a cell. -* b Boolean, n Number, e error, s String, d Date -*/ + * 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'; export interface IWorkSheetCell { @@ -341,9 +341,9 @@ export interface IWorkSheetCell { w?: string; /** - * The Excel Data Type of the cell. - * b Boolean, n Number, e error, s String, d Date - */ + * The Excel Data Type of the cell. + * b Boolean, n Number, e error, s String, d Date + */ t: ExcelDataType; /** @@ -403,18 +403,18 @@ export interface IRange { export interface IUtils { /** converts an array of arrays of JS data to a worksheet. */ - aoa_to_sheet(data: T[], opts?:any): IWorkSheet; + aoa_to_sheet(data: T[], opts?: any): IWorkSheet; /** Converts a worksheet object to an array of JSON objects */ - sheet_to_json(worksheet:IWorkSheet, opts?: { + sheet_to_json(worksheet: IWorkSheet, opts?: { raw?: boolean; range?: any; header?: "A"|number|string[]; - }):T[]; + }): T[]; /** Generates delimiter-separated-values output */ sheet_to_csv(worksheet: IWorkSheet, options?: { FS: string, RS: string }): string; /** Generates a list of the formulae (with value fallbacks) */ - sheet_to_formulae(worksheet: IWorkSheet):any; + sheet_to_formulae(worksheet: IWorkSheet): any; /** Converts 0-indexed cell address to A1 form */ encode_cell(cell: ICell): string; diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..3db14f8 --- /dev/null +++ b/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/xlsx-tests.ts b/xlsx-tests.ts index 1817ec8..6051ce3 100644 --- a/xlsx-tests.ts +++ b/xlsx-tests.ts @@ -1,8 +1,7 @@ - import xlsx = require('xlsx'); -var options:xlsx.IParsingOptions = { - cellDates:true +var options: xlsx.IParsingOptions = { + cellDates: true }; var workbook = xlsx.readFile('test.xlsx', options); @@ -10,17 +9,17 @@ var otherworkbook = xlsx.readFile('test.xlsx', {type: 'file'}); console.log(workbook.Props.Author); -var firstsheet:string = workbook.SheetNames[0]; +var firstsheet: string = workbook.SheetNames[0]; var firstworksheet = workbook.Sheets[firstsheet]; console.log(firstworksheet["A1"]); interface tester { - name:string; + name: string; age: number; } -var jsonvalues:tester[] = xlsx.utils.sheet_to_json(firstworksheet); +var jsonvalues: tester[] = xlsx.utils.sheet_to_json(firstworksheet); var csv = xlsx.utils.sheet_to_csv(firstworksheet); var formulae = xlsx.utils.sheet_to_formulae(firstworksheet); From cda05f3b455dc2e3f4473d47df7f9975d9d106d4 Mon Sep 17 00:00:00 2001 From: Wolfgang Faust Date: Fri, 12 May 2017 17:46:46 -0400 Subject: [PATCH 32/34] xlsx: Fix miscellaneous lints. --- index.d.ts | 14 +++++++------- xlsx-tests.ts | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4fc599d..2a10a7a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,21 +4,21 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /** Attempts to read filename and parse */ -export declare function readFile(filename: string, opts?: IParsingOptions): IWorkBook; +export function readFile(filename: string, opts?: IParsingOptions): IWorkBook; /** Attempts to parse data */ -export declare function read(data: any, opts?: IParsingOptions): IWorkBook; +export function read(data: any, opts?: IParsingOptions): IWorkBook; /** Attempts to write workbook data to filename */ -export declare function writeFile(data: IWorkBook, filename: string, opts?: IWritingOptions): any; +export 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 function write(data: IWorkBook, opts?: IWritingOptions): any; -export declare var utils: IUtils; +export const utils: IUtils; export interface IProperties { - LastAuthor?: string + LastAuthor?: string; Author?: string; CreatedDate?: Date; - ModifiedDate?: Date + ModifiedDate?: Date; Application?: string; AppVersion?: string; Company?: string; diff --git a/xlsx-tests.ts b/xlsx-tests.ts index 6051ce3..83d0b19 100644 --- a/xlsx-tests.ts +++ b/xlsx-tests.ts @@ -1,17 +1,17 @@ import xlsx = require('xlsx'); -var options: xlsx.IParsingOptions = { +const options: xlsx.IParsingOptions = { cellDates: true }; -var workbook = xlsx.readFile('test.xlsx', options); -var otherworkbook = xlsx.readFile('test.xlsx', {type: 'file'}); +const workbook = xlsx.readFile('test.xlsx', options); +const otherworkbook = xlsx.readFile('test.xlsx', {type: 'file'}); console.log(workbook.Props.Author); -var firstsheet: string = workbook.SheetNames[0]; +const firstsheet: string = workbook.SheetNames[0]; -var firstworksheet = workbook.Sheets[firstsheet]; +const firstworksheet = workbook.Sheets[firstsheet]; console.log(firstworksheet["A1"]); @@ -20,6 +20,6 @@ interface tester { age: number; } -var jsonvalues: tester[] = xlsx.utils.sheet_to_json(firstworksheet); -var csv = xlsx.utils.sheet_to_csv(firstworksheet); -var formulae = xlsx.utils.sheet_to_formulae(firstworksheet); +const jsonvalues: tester[] = xlsx.utils.sheet_to_json(firstworksheet); +const csv = xlsx.utils.sheet_to_csv(firstworksheet); +const formulae = xlsx.utils.sheet_to_formulae(firstworksheet); From 8385d5c889bf692710aaaba7128bbf5e8a490b96 Mon Sep 17 00:00:00 2001 From: Wolfgang Faust Date: Fri, 12 May 2017 17:46:54 -0400 Subject: [PATCH 33/34] xlsx: Linter: Require interfaces to start with 'I' The default rule for DT is that they're *not*, but changing that now would break existing usages of the xlsx typings. --- tslint.json | 7 ++++++- xlsx-tests.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tslint.json b/tslint.json index 3db14f8..5107fb4 100644 --- a/tslint.json +++ b/tslint.json @@ -1 +1,6 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dt.json", + "rules": { + "interface-name": [true, "always-prefix"] + } +} diff --git a/xlsx-tests.ts b/xlsx-tests.ts index 83d0b19..1d25a94 100644 --- a/xlsx-tests.ts +++ b/xlsx-tests.ts @@ -15,11 +15,11 @@ const firstworksheet = workbook.Sheets[firstsheet]; console.log(firstworksheet["A1"]); -interface tester { +interface ITester { name: string; age: number; } -const jsonvalues: tester[] = xlsx.utils.sheet_to_json(firstworksheet); +const jsonvalues: ITester[] = xlsx.utils.sheet_to_json(firstworksheet); const csv = xlsx.utils.sheet_to_csv(firstworksheet); const formulae = xlsx.utils.sheet_to_formulae(firstworksheet); From 1b6436c351cb0ede545b24a568dd341d6a961861 Mon Sep 17 00:00:00 2001 From: Wolfgang Faust Date: Sat, 13 May 2017 15:38:52 -0400 Subject: [PATCH 34/34] Move all files into types/ subdirectory. --- index.d.ts => types/index.d.ts | 0 tsconfig.json => types/tsconfig.json | 0 tslint.json => types/tslint.json | 0 xlsx-tests.ts => types/xlsx-tests.ts | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename index.d.ts => types/index.d.ts (100%) rename tsconfig.json => types/tsconfig.json (100%) rename tslint.json => types/tslint.json (100%) rename xlsx-tests.ts => types/xlsx-tests.ts (100%) diff --git a/index.d.ts b/types/index.d.ts similarity index 100% rename from index.d.ts rename to types/index.d.ts diff --git a/tsconfig.json b/types/tsconfig.json similarity index 100% rename from tsconfig.json rename to types/tsconfig.json diff --git a/tslint.json b/types/tslint.json similarity index 100% rename from tslint.json rename to types/tslint.json diff --git a/xlsx-tests.ts b/types/xlsx-tests.ts similarity index 100% rename from xlsx-tests.ts rename to types/xlsx-tests.ts