Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] The is no forEachAddress function definition #1681

Open
Siemienik opened this issue Apr 22, 2021 · 2 comments
Open

[BUG] The is no forEachAddress function definition #1681

Siemienik opened this issue Apr 22, 2021 · 2 comments

Comments

@Siemienik
Copy link
Member

馃悰 Bug Report

Type definition has no forEachAddress function definition.

exceljs/index.d.ts

Lines 927 to 972 in 2ab468b

export interface Range extends Location {
sheetName: string;
tl: string;
$t$l: string;
br: string;
$b$r: string;
range: string;
$range: string;
shortRange: string;
$shortRange: string;
count: number;
decode(): void;
decode(v: Range): void;
decode(v: string): void;
decode(v: Location): void;
decode(top: number, left: number, bottom: number, right: number, sheetName?: string): void;
decode(tl: string, br: string, sheetName?: string): void;
decode(v: [string, string]): void;
decode(v: [string, string, string]): void;
decode(v: [number, number, number, number]): void;
decode(v: [number, number, number, number, string]): void;
expand(top: number, left: number, bottom: number, right: number): void;
expandRow(row: Row): void;
expandToAddress(addressStr: string): void;
toString(): string;
intersects(other: Range): boolean;
contains(addressStr: string): boolean;
containsEx(address: Partial<{
sheetName: string;
row: number;
col: number;
}>): boolean;
}

exceljs/lib/doc/range.js

Lines 248 to 254 in 2ab468b

forEachAddress(cb) {
for (let col = this.left; col <= this.right; col++) {
for (let row = this.top; row <= this.bottom; row++) {
cb(colCache.encodeAddress(row, col), row, col);
}
}
}

Lib version: 4.2.1

Steps To Reproduce

  const style = {numFmt:'### ### ### ###'};
  const range = new Range('B5','C99');

  // There is no `forEachAddress` in a index.d.ts
  range.forEachAddress((address) => {worksheet.getCell(address).style = {...style} });

The expected behavior:

No error

Current workaround

By adding @ts-ignore

  const style = {numFmt:'### ### ### ###'};

  const range = new Range('B5','C99');

  // There is no `forEachAddress` in a index.d.ts
  // @ts-ignore 
  range.forEachAddress((address) => {worksheet.getCell(address).style = {...style} });
@Siemienik Siemienik self-assigned this Apr 22, 2021
@Siemienik Siemienik changed the title [BUG] The is no [BUG] The is no forEachAddress function definition Apr 22, 2021
@skypesky
Copy link
Contributor

skypesky commented Apr 22, 2021

@Siemienik hi,Siemienik,

Range is a Interface,it is not a Class.

const range: Range = new Range('B5','C99'); // Error

exceljs/index.d.ts

Lines 927 to 928 in 2ab468b

export interface Range extends Location {
sheetName: string;

@Siemienik
Copy link
Member Author

Siemienik commented Apr 22, 2021

Yeah, our types are bad 馃槥
That why I'm a big fan to convert all lib into typescript, which will finally resolve all bugs with types.

Here you have example how to import this class:

https://github.com/Siemienik/XToolset/blob/f6f0a7de85d719fb7937a19d61ca9a09c96dc6d8/packages/xlsx-renderer/src/cell/ForEachCell.ts#L6-L7

@Siemienik Siemienik removed their assignment Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants