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

Line break in formula causes exception #62

Closed
cc-a opened this issue Dec 17, 2020 · 2 comments
Closed

Line break in formula causes exception #62

cc-a opened this issue Dec 17, 2020 · 2 comments

Comments

@cc-a
Copy link

cc-a commented Dec 17, 2020

Describe the bug
Trying to to load a Spreadsheet with a formula containing a linebreak fails with an exception:

File "/home/ccaveayl/projects/formulas/model2050.py", line 36, in init
self.model = formulas.ExcelModel().loads(str(xlsx_path)).finish()
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/excel/init.py", line 87, in loads
self.load(filename)
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/excel/init.py", line 92, in load
self.pushes(*book.worksheets, context=context)
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/excel/init.py", line 97, in pushes
self.push(ws, context=context)
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/excel/init.py", line 110, in push
self.add_cell(
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/excel/init.py", line 209, in add_cell
cell = Cell(crd, val, context=ctx).compile(references=references)
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/cell.py", line 73, in init
self.tokens, self.builder = self.parser.ast(value, context=context)
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/parser.py", line 53, in ast
token.ast(tokens, stack, builder)
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/tokens/operator.py", line 91, in ast
pred = self.pred
File "/home/ccaveayl/projects/formulas/.venv/lib/python3.9/site-packages/formulas/tokens/operator.py", line 76, in pred
return self._precedences[self.name]
KeyError: '\n'

To Reproduce

A minimal example is provided by test_line_break.xlsx.

Simply try to load this file with formulas.

Expected behavior

Spreadsheet should load correctly with line break ignored

Screenshots

N/A

Desktop (please complete the following information):

  • OS: Arch Linux
  • Version: N/A

Additional context

I've temporarily resolved this by changing:

self.tokens, self.builder = self.parser.ast(value, context=context)

to

    self.tokens, self.builder = self.parser.ast(value.replace("\n", ""), context=context) 

I suspect there is a better approach to resolving however. If you're able to advise on the best approach I'd be happy to put together a PR for this.

@cc-a
Copy link
Author

cc-a commented Dec 17, 2020

Apologies just noticed this may be a duplicate of #61

@cc-a
Copy link
Author

cc-a commented Dec 17, 2020

Already resolved on dev branch.

@cc-a cc-a closed this as completed Dec 17, 2020
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