def eval_pointers_from_ast(self, ast, node, cell): results = [] context = cell["sheet"] if (node.token.tvalue == "INDEX" or node.token.tvalue == "OFFSET"): pointer_string = reverse_rpn(node, ast) expression = node.emit(ast, context=context) if expression.startswith("self.eval_ref"): expression_type = "value" else: expression_type = "formula" try: pointer_value = eval(expression) except Exception as e: if self.debug: print 'EXCEPTION raised in eval_pointers: EXPR', expression, cell[ "address"] raise Exception("Problem evalling: %s for %s, %s" % (e, cell["address"], expression)) return { "formula": pointer_string, "value": pointer_value, "expression_type": expression_type } else: for c in node.children(ast): results.append(self.eval_pointers_from_ast(ast, c, cell)) return list(flatten(results, only_lists=True))
def eval_pointers_from_ast(self, ast, node, cell): results = [] context = cell["sheet"] if (node.token.tvalue == "INDEX" or node.token.tvalue == "OFFSET"): pointer_string = reverse_rpn(node, ast) expression = node.emit(ast, context=context) if expression.startswith("self.eval_ref"): expression_type = "value" else: expression_type = "formula" try: pointer_value = eval(expression) except Exception as e: if self.debug: print('EXCEPTION raised in eval_pointers: EXPR', expression, cell["address"]) raise Exception("Problem evalling: %s for %s, %s" % (e, cell["address"], expression)) return {"formula":pointer_string, "value": pointer_value, "expression_type": expression_type} else: for c in node.children(ast): results.append(self.eval_pointers_from_ast(ast, c, cell)) return list(flatten(results, only_lists = True))
def get_arguments_from_ast(self, ast, node, sheet): arguments = [] for c in node.children(ast): if c.tvalue == ":": arg_range = reverse_rpn(c, ast) for elem in resolve_range(arg_range, False, sheet)[0]: arguments += [elem] if c.ttype == "operand": if not is_number(c.tvalue): if sheet is not None and "!" not in c.tvalue and c.tvalue not in self.named_ranges: arguments += [sheet + "!" + c.tvalue] else: arguments += [c.tvalue] else: arguments += [self.get_arguments_from_ast(ast, c, sheet)] return arguments
def get_arguments_from_ast(self, ast, node, sheet): arguments = [] for c in node.children(ast): if c.tvalue == ":": arg_range = reverse_rpn(c, ast) for elem in resolve_range(arg_range, False, sheet)[0]: arguments += [elem] if c.ttype == "operand": if not is_number(c.tvalue): if sheet is not None and "!" not in c.tvalue and c.tvalue not in self.named_ranges: arguments += [sheet + "!" + c.tvalue] else: arguments += [c.tvalue] else: arguments += [self.get_arguments_from_ast(ast, c, sheet)] return arguments