8000 Worksheet Dimensions: fix examples by automatically deducing range · Issue #1601 · SheetJS/sheetjs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Worksheet Dimensions: fix examples by automatically deducing range #1601

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Vanuan opened this issue Aug 15, 2019 · 2 comments
Open

Worksheet Dimensions: fix examples by automatically deducing range #1601

Vanuan opened this issue Aug 15, 2019 · 2 comments

Comments

@Vanuan
Copy link
Vanuan commented Aug 15, 2019

There's this !ref property that corresponds to Worksheet Dimensions.

Documentation states:

It specifies the row and column bounds of used cells in the worksheet
When an entire column is formatted, only the first cell in that column is considered used.

Specifically the ref property:

The row and column bounds of all cells in this worksheet. Corresponds to the range that would contain all elements written under . Does not support whole column or whole row reference notation.

The can be various interpretation on whether "used cells" refers to formatting or to cell elements.

Anyway, ref property is unreliable. So I suggest fixing examples to determine range with the following code:

    const cells = Object.keys(sheet).map((key) => dc(key))
    const maxRow = maxBy(cells, 'r').r;
    const maxCol = maxBy(cells, 'c').c;

    range.max = {r: maxRow, c: maxCol};

@SheetJSDev
Copy link
Contributor

The wiki has a sample for updating worksheet range

The "fix" is to change the parsers to recalculate the range, not pushing the code to end users

@Nairolf92
Copy link

Since that the link to the wiki isn't working anymore, here is the function from the new documentation that updates the "real" range of the spreadsheet

function update_sheet_range(ws) {
  var range = {s:{r:Infinity, c:Infinity},e:{r:0,c:0}};
  Object.keys(ws).filter(function(x) { return x.charAt(0) != "!"; }).map(XLSX.utils.decode_cell).forEach(function(x) {
    range.s.c = Math.min(range.s.c, x.c); range.s.r = Math.min(range.s.r, x.r);
    range.e.c = Math.max(range.e.c, x.c); range.e.r = Math.max(range.e.r, x.r);
  });
  ws['!ref'] = XLSX.utils.encode_range(range);
}

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

3 participants
0