All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Explore the source code of the class

# -*- coding: windows-1252 -*-

import ExcelFormulaParser, ExcelFormulaLexer
import struct
from antlr import ANTLRException

class Formula(object):
    __slots__ = ["__init__",  "__s", "__parser", "__sheet_refs", "__xcall_refs"]

    def __init__(self, s):
            self.__s = s
            lexer = ExcelFormulaLexer.Lexer(s)
            self.__parser = ExcelFormulaParser.Parser(lexer)
            self.__sheet_refs = self.__parser.sheet_references
            self.__xcall_refs = self.__parser.xcall_references
        except ANTLRException, e:
            # print e
            raise ExcelFormulaParser.FormulaParseException, "can't parse formula " + s

    def get_references(self):
        return self.__sheet_refs, self.__xcall_refs

    def patch_references(self, patches):
        for offset, idx in patches:
            self.__parser.rpn = self.__parser.rpn[:offset] + struct.pack('