summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2022-08-17 10:59:52 +0800
committerGitHub <noreply@github.com>2022-08-17 10:59:52 +0800
commitd1e76fc432ac5c9bde99591ec5e88e46b62d9c3d (patch)
tree8e5c13bff106593ecd5dbabbd0a4fae4fefe901e
parent551fb8a9e4b03fe718a339e75aeacc8b5581378a (diff)
This closes #1319, fix calculate error for formula with negative symbol
- Update unit test and comment for the functions
-rw-r--r--calc.go8
-rw-r--r--calc_test.go1
-rw-r--r--comment.go2
-rw-r--r--rows.go1
4 files changed, 7 insertions, 5 deletions
diff --git a/calc.go b/calc.go
index 0cdb91e..25595d6 100644
--- a/calc.go
+++ b/calc.go
@@ -1234,7 +1234,7 @@ func calculate(opdStack *Stack, opt efp.Token) error {
return ErrInvalidFormula
}
opd := opdStack.Pop().(formulaArg)
- opdStack.Push(newNumberFormulaArg(0 - opd.Number))
+ opdStack.Push(newNumberFormulaArg(0 - opd.ToNumber().Number))
}
if opt.TValue == "-" && opt.TType == efp.TokenTypeOperatorInfix {
if opdStack.Len() < 2 {
@@ -1647,10 +1647,10 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er
var value, expected float64
var e error
prepareValue := func(val, cond string) (value float64, expected float64, err error) {
- percential := 1.0
+ percentile := 1.0
if strings.HasSuffix(cond, "%") {
cond = strings.TrimSuffix(cond, "%")
- percential /= 100
+ percentile /= 100
}
if value, err = strconv.ParseFloat(val, 64); err != nil {
return
@@ -1658,7 +1658,7 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er
if expected, err = strconv.ParseFloat(cond, 64); err != nil {
return
}
- expected *= percential
+ expected *= percentile
return
}
switch criteria.Type {
diff --git a/calc_test.go b/calc_test.go
index 47cd806..5822135 100644
--- a/calc_test.go
+++ b/calc_test.go
@@ -491,6 +491,7 @@ func TestCalcCellValue(t *testing.T) {
// COS
"=COS(0.785398163)": "0.707106781467586",
"=COS(0)": "1",
+ "=-COS(0)": "-1",
"=COS(COS(0))": "0.54030230586814",
// COSH
"=COSH(0)": "1",
diff --git a/comment.go b/comment.go
index 0794986..82d1f88 100644
--- a/comment.go
+++ b/comment.go
@@ -177,7 +177,7 @@ func (f *File) addDrawingVML(commentID int, drawingVML, cell string, lineCount,
},
},
}
- // load exist comment shapes from xl/drawings/vmlDrawing%d.vml (only once)
+ // load exist comment shapes from xl/drawings/vmlDrawing%d.vml
d := f.decodeVMLDrawingReader(drawingVML)
if d != nil {
for _, v := range d.Shape {
diff --git a/rows.go b/rows.go
index 9eef628..5808530 100644
--- a/rows.go
+++ b/rows.go
@@ -179,6 +179,7 @@ func (rows *Rows) Columns(opts ...Options) ([]string, error) {
return rowIterator.columns, rowIterator.err
}
+// extractRowOpts extract row element attributes.
func extractRowOpts(attrs []xml.Attr) RowOpts {
rowOpts := RowOpts{Height: defaultRowHeight}
if styleID, err := attrValToInt("s", attrs); err == nil && styleID > 0 && styleID < MaxCellStyles {