Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
修订版 | d1e76fc432ac5c9bde99591ec5e88e46b62d9c3d (tree) |
---|---|
时间 | 2022-08-17 11:59:52 |
作者 | ![]() |
Commiter | GitHub |
This closes #1319, fix calculate error for formula with negative symbol
- Update unit test and comment for the functions
@@ -1234,7 +1234,7 @@ func calculate(opdStack *Stack, opt efp.Token) error { | ||
1234 | 1234 | return ErrInvalidFormula |
1235 | 1235 | } |
1236 | 1236 | opd := opdStack.Pop().(formulaArg) |
1237 | - opdStack.Push(newNumberFormulaArg(0 - opd.Number)) | |
1237 | + opdStack.Push(newNumberFormulaArg(0 - opd.ToNumber().Number)) | |
1238 | 1238 | } |
1239 | 1239 | if opt.TValue == "-" && opt.TType == efp.TokenTypeOperatorInfix { |
1240 | 1240 | if opdStack.Len() < 2 { |
@@ -1647,10 +1647,10 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er | ||
1647 | 1647 | var value, expected float64 |
1648 | 1648 | var e error |
1649 | 1649 | prepareValue := func(val, cond string) (value float64, expected float64, err error) { |
1650 | - percential := 1.0 | |
1650 | + percentile := 1.0 | |
1651 | 1651 | if strings.HasSuffix(cond, "%") { |
1652 | 1652 | cond = strings.TrimSuffix(cond, "%") |
1653 | - percential /= 100 | |
1653 | + percentile /= 100 | |
1654 | 1654 | } |
1655 | 1655 | if value, err = strconv.ParseFloat(val, 64); err != nil { |
1656 | 1656 | return |
@@ -1658,7 +1658,7 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er | ||
1658 | 1658 | if expected, err = strconv.ParseFloat(cond, 64); err != nil { |
1659 | 1659 | return |
1660 | 1660 | } |
1661 | - expected *= percential | |
1661 | + expected *= percentile | |
1662 | 1662 | return |
1663 | 1663 | } |
1664 | 1664 | switch criteria.Type { |
@@ -491,6 +491,7 @@ func TestCalcCellValue(t *testing.T) { | ||
491 | 491 | // COS |
492 | 492 | "=COS(0.785398163)": "0.707106781467586", |
493 | 493 | "=COS(0)": "1", |
494 | + "=-COS(0)": "-1", | |
494 | 495 | "=COS(COS(0))": "0.54030230586814", |
495 | 496 | // COSH |
496 | 497 | "=COSH(0)": "1", |
@@ -177,7 +177,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount, | ||
177 | 177 | }, |
178 | 178 | }, |
179 | 179 | } |
180 | - // load exist comment shapes from xl/drawings/vmlDrawing%d.vml (only once) | |
180 | + // load exist comment shapes from xl/drawings/vmlDrawing%d.vml | |
181 | 181 | d := f.decodeVMLDrawingReader(drawingVML) |
182 | 182 | if d != nil { |
183 | 183 | for _, v := range d.Shape { |
@@ -179,6 +179,7 @@ func (rows *Rows) Columns(opts ...Options) ([]string, error) { | ||
179 | 179 | return rowIterator.columns, rowIterator.err |
180 | 180 | } |
181 | 181 | |
182 | +// extractRowOpts extract row element attributes. | |
182 | 183 | func extractRowOpts(attrs []xml.Attr) RowOpts { |
183 | 184 | rowOpts := RowOpts{Height: defaultRowHeight} |
184 | 185 | if styleID, err := attrValToInt("s", attrs); err == nil && styleID > 0 && styleID < MaxCellStyles { |