Skip to content

removal of scoped named expressions #641

Closed

Description

@izulin

Description

  1. Removing sheet does not remove scoped named expressions assigned to this sheet.
  2. Trying to remove named expression scoped with nonexistent sheet results in an error.

1+2 gives:

    const engine = HyperFormula.buildFromSheets({'Sheet1': [[]], 'Sheet2': [[]]})
    engine.addNamedExpression('TRUE', true, 'Sheet1')
    expect(engine.listNamedExpressions()).toEqual(['TRUE'])
    engine.removeSheet('Sheet1')
    expect(engine.listNamedExpressions()).toEqual(['TRUE']) //named expression is still registered
    engine.removeNamedExpression('TRUE', 'Sheet1') //throws exception Error: There's no sheet with name 'Sheet1'

(note: this is on my private branch where listNamedExpressions() produces ALL named expressions)

Steps to reproduce

Demo

Your environment

  • HyperFormula version:
  • Browser Name and version:
  • Operating System:

Links

Activity

  1. added
    Bug
    on Apr 20, 2021
  2. self-assigned this
    on Apr 20, 2021
  3. izulin commented on Apr 20, 2021

    @izulin
    ContributorAuthor

    Here is my take:

    • we cannot add named expressions scoped with nonexistent sheets (preload named expression waiting for sheet to appear)
    • scoped named expressions are stored internally assigned to sheet number, not to sheet name
    • hence, we should remove all named expressions scoped with sheet that is going to be removed
  4. wojciechczerniak commented on Apr 21, 2021

    @wojciechczerniak
    Contributor

    I agree.

    we cannot add named expressions scoped with nonexistent sheets (preload named expression waiting for sheet to appear)

    Just this one will be problematic. Once you load sheet with named expressions there will be #REF! errors or it will use global scoped ones if they exists, the results may be unexpected. We should create a test for both scenarios and figure out the solution.

    First idea, batch:

    hf.batch(() => {
      hf.addSheet()
      hf.addNamedExpression()
      hf.setSheetContent()
    });

    Second idea, extend addSheet method:

    hf.addSheet(sheetName, sheetData, namedExpressions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions