Skip to content

Commit

Permalink
fix(excel): Skip function compilation for string cells.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinci1it2000 committed May 10, 2020
1 parent 52ffdf0 commit 844dbf8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
11 changes: 7 additions & 4 deletions formulas/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def __init__(self, func, parse_args, parse_kwargs):

def __call__(self, *args, **kwargs):
try:
return self.func(*self.parse_args(*args), **self.parse_kwargs(**kwargs))
return self.func(
*self.parse_args(*args), **self.parse_kwargs(**kwargs)
)
except sh.DispatcherError as ex:
if isinstance(ex.ex, NotImplementedError):
return Error.errors['#NAME?']
Expand Down Expand Up @@ -63,14 +65,15 @@ def format_output(rng, value):
class Cell:
parser = Parser()

def __init__(self, reference, value, context=None):
def __init__(self, reference, value, context=None, check_formula=True):
self.func = self.range = self.inputs = self.output = None
if reference is not None:
self.range = Ranges().push(reference, context=context)
self.output = self.range.ranges[0]['name']
self.tokens, self.builder, self.value = (), None, sh.EMPTY
if isinstance(value, str) and self.parser.is_formula(value):
self.tokens, self.builder = self.parser.ast(value, context=context)
prs = self.parser
if check_formula and isinstance(value, str) and prs.is_formula(value):
self.tokens, self.builder = prs.ast(value, context=context)
elif value is not None:
self.value = value

Expand Down
7 changes: 6 additions & 1 deletion formulas/excel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ def add_cell(self, cell, context, references=None, formula_references=None,
crd = formula_references.get(crd, crd)
val = cell.value
val = cell.data_type == 'f' and val[:2] == '==' and val[1:] or val
cell = Cell(crd, val, context=ctx).compile(references=references)
check_formula = cell.data_type != 's'
cell = Cell(crd, val, context=ctx, check_formula=check_formula).compile(
references=references
)
if cell.output in self.cells:
return
if cell.value is not sh.EMPTY:
Expand Down Expand Up @@ -307,6 +310,8 @@ def write(self, books=None, solution=None, dirpath=None):
elif isinstance(v, XlError):
v = str(v)
c.value = v
if c.data_type == 'f':
c.data_type = 's'
except AttributeError:
pass
if dirpath:
Expand Down
Binary file modified test/test_files/test.xlsx
Binary file not shown.

0 comments on commit 844dbf8

Please sign in to comment.