def transform(self, formula, objstr): self.formula = formula # replace all single cell refs with equivalent data reference strings refs = self.ref_rx.findall(self.formula) for ref in refs: dataref = rf.cellref2dataref(ref, objstr) self.formula = re.sub(re.escape("[" + ref + "]"), dataref, self.formula) return self.formula
def __init__(self, ref, sheetobj): self.ref = ref self.sheetobj = sheetobj self.formula = sheetobj.formulas[self.ref] self.dataref = rf.cellref2dataref(self.ref, 'self.sheetobj.data') self.output = [] # tranform lexical elements into execable strings for trnsltr in lx.translators: self.formula = trnsltr.transform(self.formula, 'self.sheetobj.data') # get cell output and update sheetobj.data exec 'self.output = ' + self.formula exec self.dataref + '= self.output'