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

Already on GitHub? Sign in to your account

support for set_value and evaluate with defined names #153

Open
codinguncut opened this issue Oct 14, 2022 · 0 comments
Open

support for set_value and evaluate with defined names #153

codinguncut opened this issue Oct 14, 2022 · 0 comments

Comments

@codinguncut
Copy link

codinguncut commented Oct 14, 2022

As far as I can tell it is not possible to use "defined names" in the set_value and evaluate methods.

excel = ExcelCompiler(filename='simple.xlsx')
excel.evaluate('together')
Traceback (most recent call last):
  File "C:\Users\sinea\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pycel\excelcompiler.py", line 851, in _evaluate_non_iterative
    address = AddressRange.create(address)
  File "C:\Users\sinea\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pycel\excelutil.py", line 343, in create
    addr_tuple, sheetname = range_boundaries(
  File "C:\Users\sinea\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pycel\excelutil.py", line 752, in range_boundaries
    raise ValueError(f"{address} is not a valid coordinate or range")
ValueError: together is not a valid coordinate or range

It would be nice if this could be supported natively.

Possible workaround below, unless I have completely missed the point.
Also, the documentation for AddressCell and AddressRange is a bit weird in requiring to pass in a _Cell when it appears that what needs to be passed in is an ExcelCompiler, since _Cell has no attribute .excel.defined_names

   class PycelWrapper(ExcelCompiler):
        def __init__(self, *args, **kwargs):
            self.compiler = ExcelCompiler(*args, **kwargs)

        def evaluate(self, address, *args, **kwargs):
            range = AddressRange.create(address, *args, cell=self, **kwargs)
            return self.compiler.evaluate(range, *args, **kwargs)

        def set_value(self, address, *args, **kwargs):
            cell = AddressCell.create(address, *args, cell=self, **kwargs)
            return self.compiler.set_value(cell, *args, **kwargs)

        def __getattr__(self, name):
            return getattr(self.compiler, name)

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

1 participant