exceljs / exceljs

Excel Workbook Manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] getSheetValues() typescript definition is incorrect

danielnitsche opened this issue Β· comments

πŸ› Bug Report

Lib version: 3.9.0

Steps To Reproduce

getSheetValues() is defined as:

	/**
	 * return all rows as sparse array
	 */
	getSheetValues(): Row[];

So one would expect a Row type to be returned.

The expected behaviour:

However reviewing the code for this function:

  // return all rows as sparse array
  getSheetValues() {
    const rows = [];
    this._rows.forEach(row => {
      if (row) {
        rows[row.number] = row.values;
      }
    });
    return rows;
  }

A plain array is being returned instead.

Possible solution (optional, but very helpful):

Update type definition to

	/**
	 * return all rows as sparse array
	 */
	getSheetValues(): Cell[][];

The array may be any type of value, string, object, etc.
issue_1254

/**
* return all rows as sparse array
*/
getSheetValues(): any[];

@Alanscut we shout avoid using of any. It means that we haven't idea what happens.

As we can find here:

exceljs/index.d.ts

Lines 536 to 540 in 2d82154

/**
* Get a row as a sparse array
*/
// readonly values: CellValue[];
values: CellValue[] | { [key: string]: CellValue };

the following code should works great:

type RowValues=CellValue[] | { [key: string]: CellValue }; 
/*...*/
getSheetValues(): RowValues[];

P.S. I wrote it in comment without test, please apologize if I made a mistake.