diff --git a/calc.go b/calc.go index ddc07a7..532b7a4 100644 --- a/calc.go +++ b/calc.go @@ -815,6 +815,27 @@ func (f *File) calcCellValue(ctx *calcContext, sheet, cell string) (result formu 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] diff --git a/go.mod b/go.mod index a4a0a74..8286e47 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/xuri/excelize/v2 +module git.qcode.fun/imhven/excelize-formula/v2 go 1.16