From 2904af4653e698c525db62ec8e493d75a62f9ab3 Mon Sep 17 00:00:00 2001 From: Miles Chesney Date: Thu, 23 Jul 2020 18:17:49 +0100 Subject: [PATCH] preserve cells with constant values through resets --- koala/Spreadsheet.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/koala/Spreadsheet.py b/koala/Spreadsheet.py index 56d50451..1a0961c1 100644 --- a/koala/Spreadsheet.py +++ b/koala/Spreadsheet.py @@ -216,10 +216,13 @@ def build_spreadsheet(self, G, cellmap, named_ranges, pointers = set(), outputs self.debug = debug self.fixed_cells = {} - # make sure that all cells that don't have a value defined are updated. for cell in self.cellmap.values(): + # make sure that all cells that don't have a value defined are updated, if cell.value is None and cell.formula is not None: cell.needs_update = True + # and that constant values remain through resets. + if cell.formula is None and cell.value is not None: + cell.should_eval = 'never' def activate_history(self): @@ -836,6 +839,19 @@ def cell_free(self, address=None): except KeyError: raise Exception('Cell %s not in cellmap' % address) + def cell_reveal(self, address): + ''' for debugging purposes - prints interesting things about a cell ''' + + if address in self.cellmap: + cell = self.cellmap[address] + cell_dict = cell.asdict() + cell_dict['need update'] = cell.need_update + logging.info('{}'.format(cell_dict)) + return + else: + logging.info('{} not in spreadsheet'.format(address)) + return + def print_value_tree(self,addr,indent): cell = self.cellmap[addr] logging.debug("%s %s = %s" % (" "*indent,addr,cell.value)) @@ -964,7 +980,11 @@ def cell_evaluate(self, address): return ExcelError('#NULL', 'Cell %s is empty' % address) # no formula, fixed value - if cell.should_eval == 'normal' and not cell.need_update and cell.value is not None or not cell.formula or cell.should_eval == 'never': + if ( cell.should_eval == 'normal' + and not cell.need_update + and cell.value is not None + or not cell.formula + or cell.should_eval == 'never' ): return cell.value if cell.value != '' else None try: if cell.is_range: