feat: add CalcFormulaValue method

pull/2/head
xs 3 years ago
parent c49e7aab30
commit f855ddfc46

@ -475,6 +475,27 @@ func (f *File) CalcCellValue(sheet, cell string) (result string, err error) {
return
}
func (f *File) CalcFormulaValue(sheet, formula string) (result string, err error) {
var (
token efp.Token
)
ps := efp.ExcelParser()
tokens := ps.Parse(formula)
if tokens == nil {
return
}
if token, err = f.evalInfixExp(sheet, "", tokens); err != nil {
return
}
result = token.TValue
isNum, precision := isNumeric(result)
if isNum && precision > 15 {
num, _ := roundPrecision(result)
result = strings.ToUpper(num)
}
return
}
// getPriority calculate arithmetic operator priority.
func getPriority(token efp.Token) (pri int) {
pri = tokenPriority[token.TValue]

Loading…
Cancel
Save