• R/O
  • HTTP
  • SSH
  • HTTPS

excelize: 提交

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets


Commit MetaInfo

修订版d1e76fc432ac5c9bde99591ec5e88e46b62d9c3d (tree)
时间2022-08-17 11:59:52
作者xuri <xuri.me@gmai...>
CommiterGitHub

Log Message

This closes #1319, fix calculate error for formula with negative symbol

- Update unit test and comment for the functions

更改概述

差异

--- a/calc.go
+++ b/calc.go
@@ -1234,7 +1234,7 @@ func calculate(opdStack *Stack, opt efp.Token) error {
12341234 return ErrInvalidFormula
12351235 }
12361236 opd := opdStack.Pop().(formulaArg)
1237- opdStack.Push(newNumberFormulaArg(0 - opd.Number))
1237+ opdStack.Push(newNumberFormulaArg(0 - opd.ToNumber().Number))
12381238 }
12391239 if opt.TValue == "-" && opt.TType == efp.TokenTypeOperatorInfix {
12401240 if opdStack.Len() < 2 {
@@ -1647,10 +1647,10 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er
16471647 var value, expected float64
16481648 var e error
16491649 prepareValue := func(val, cond string) (value float64, expected float64, err error) {
1650- percential := 1.0
1650+ percentile := 1.0
16511651 if strings.HasSuffix(cond, "%") {
16521652 cond = strings.TrimSuffix(cond, "%")
1653- percential /= 100
1653+ percentile /= 100
16541654 }
16551655 if value, err = strconv.ParseFloat(val, 64); err != nil {
16561656 return
@@ -1658,7 +1658,7 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er
16581658 if expected, err = strconv.ParseFloat(cond, 64); err != nil {
16591659 return
16601660 }
1661- expected *= percential
1661+ expected *= percentile
16621662 return
16631663 }
16641664 switch criteria.Type {
--- a/calc_test.go
+++ b/calc_test.go
@@ -491,6 +491,7 @@ func TestCalcCellValue(t *testing.T) {
491491 // COS
492492 "=COS(0.785398163)": "0.707106781467586",
493493 "=COS(0)": "1",
494+ "=-COS(0)": "-1",
494495 "=COS(COS(0))": "0.54030230586814",
495496 // COSH
496497 "=COSH(0)": "1",
--- a/comment.go
+++ b/comment.go
@@ -177,7 +177,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
177177 },
178178 },
179179 }
180- // load exist comment shapes from xl/drawings/vmlDrawing%d.vml (only once)
180+ // load exist comment shapes from xl/drawings/vmlDrawing%d.vml
181181 d := f.decodeVMLDrawingReader(drawingVML)
182182 if d != nil {
183183 for _, v := range d.Shape {
--- a/rows.go
+++ b/rows.go
@@ -179,6 +179,7 @@ func (rows *Rows) Columns(opts ...Options) ([]string, error) {
179179 return rowIterator.columns, rowIterator.err
180180 }
181181
182+// extractRowOpts extract row element attributes.
182183 func extractRowOpts(attrs []xml.Attr) RowOpts {
183184 rowOpts := RowOpts{Height: defaultRowHeight}
184185 if styleID, err := attrValToInt("s", attrs); err == nil && styleID > 0 && styleID < MaxCellStyles {
Show on old repository browser