From 6912bdb2d449525d65244d461e7afe2670d57a75 Mon Sep 17 00:00:00 2001 From: Yifei Date: Thu, 5 Sep 2024 10:25:52 +0800 Subject: [PATCH] fix: Add DenseSheetData type (#3195) --- modules/83_numbers.ts | 6 +++--- types/index.d.ts | 18 ++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/modules/83_numbers.ts b/modules/83_numbers.ts index 188a4e0..7ea6518 100644 --- a/modules/83_numbers.ts +++ b/modules/83_numbers.ts @@ -4,7 +4,7 @@ /* these are type imports and do not show up in the generated JS */ import { CFB$Container, CFB$Entry } from 'cfb'; import { WorkBook, WorkSheet, Range, CellObject, ParsingOptions, WritingOptions, DenseWorkSheet, Comments } from '../'; -import type { utils, NumberFormat } from "../"; +import type { utils, NumberFormat, DenseSheetData } from "../"; declare var encode_col: typeof utils.encode_col; declare var encode_row: typeof utils.encode_row; @@ -1697,7 +1697,7 @@ function write_numbers_tma(cfb: CFB$Container, deps: Dependents, ws: WorkSheet, if(trunc) console.error(`Truncating to ${encode_range(range)}`); /* preprocess data and build up shared string table */ - var data: CellObject[][] = []; + var data: DenseSheetData = []; if(ws["!data"]) data = ws["!data"]; else { var colstr: string[] = []; @@ -1708,7 +1708,7 @@ function write_numbers_tma(cfb: CFB$Container, deps: Dependents, ws: WorkSheet, for(_C = 0; _C <= range.e.c; ++_C) { var _cell = ws[colstr[_C] + _R]; if(!_cell) continue; - data[R_][_C] = _cell; + data[R_]![_C] = _cell; } } } diff --git a/types/index.d.ts b/types/index.d.ts index b91078a..5d1811f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -575,14 +575,14 @@ export interface Sheet { * Dense-mode store cells in the '!data' key * Special keys start with '!' */ - [cell: string]: CellObject | CellObject[][] | SheetKeys | any; + [cell: string]: CellObject | DenseSheetData | SheetKeys | any; /** * Dense-mode worksheets store data in an array of arrays * * Cells are accessed with sheet['!data'][R][C] (where R and C are 0-indexed) */ - '!data'?: CellObject[][]; + '!data'?: DenseSheetData; /** Sheet type */ '!type'?: SheetType; @@ -599,15 +599,16 @@ export interface DenseSheet extends Sheet { * Special keys start with '!' * Dense-mode worksheets store data in the '!data' key */ - [cell: string]: CellObject[][] | SheetKeys | any; + [cell: string]: DenseSheetData | SheetKeys | any; /** * Dense-mode worksheets store data in an array of arrays * * Cells are accessed with sheet['!data'][R][C] (where R and C are 0-indexed) */ - '!data': CellObject[][]; + '!data': DenseSheetData; } +export type DenseSheetData = ((CellObject|undefined)[]|undefined)[]; /** General object representing a sparse Sheet (worksheet or chartsheet) */ export interface SparseSheet extends Sheet { /** @@ -650,14 +651,7 @@ export interface WorkSheet extends Sheet { '!autofilter'?: AutoFilterInfo; } /** Dense Worksheet Object */ -export interface DenseWorkSheet extends DenseSheet { - /** - * Dense-mode worksheets store data in an array of arrays - * - * Cells are accessed with sheet['!data'][R][C] (where R and C are 0-indexed) - */ - '!data': CellObject[][]; -} +export interface DenseWorkSheet extends DenseSheet {} /** * Worksheet Object with CellObject type