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

- Update unit test and comment for the functions
This commit is contained in:
xuri 2022-08-17 10:59:52 +08:00 committed by GitHub
parent 551fb8a9e4
commit d1e76fc432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 5 deletions

View File

@ -1234,7 +1234,7 @@ func calculate(opdStack *Stack, opt efp.Token) error {
return ErrInvalidFormula return ErrInvalidFormula
} }
opd := opdStack.Pop().(formulaArg) 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 opt.TValue == "-" && opt.TType == efp.TokenTypeOperatorInfix {
if opdStack.Len() < 2 { if opdStack.Len() < 2 {
@ -1647,10 +1647,10 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er
var value, expected float64 var value, expected float64
var e error var e error
prepareValue := func(val, cond string) (value float64, expected float64, err error) { prepareValue := func(val, cond string) (value float64, expected float64, err error) {
percential := 1.0 percentile := 1.0
if strings.HasSuffix(cond, "%") { if strings.HasSuffix(cond, "%") {
cond = strings.TrimSuffix(cond, "%") cond = strings.TrimSuffix(cond, "%")
percential /= 100 percentile /= 100
} }
if value, err = strconv.ParseFloat(val, 64); err != nil { if value, err = strconv.ParseFloat(val, 64); err != nil {
return return
@ -1658,7 +1658,7 @@ func formulaCriteriaEval(val string, criteria *formulaCriteria) (result bool, er
if expected, err = strconv.ParseFloat(cond, 64); err != nil { if expected, err = strconv.ParseFloat(cond, 64); err != nil {
return return
} }
expected *= percential expected *= percentile
return return
} }
switch criteria.Type { switch criteria.Type {

View File

@ -491,6 +491,7 @@ func TestCalcCellValue(t *testing.T) {
// COS // COS
"=COS(0.785398163)": "0.707106781467586", "=COS(0.785398163)": "0.707106781467586",
"=COS(0)": "1", "=COS(0)": "1",
"=-COS(0)": "-1",
"=COS(COS(0))": "0.54030230586814", "=COS(COS(0))": "0.54030230586814",
// COSH // COSH
"=COSH(0)": "1", "=COSH(0)": "1",

View File

@ -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) d := f.decodeVMLDrawingReader(drawingVML)
if d != nil { if d != nil {
for _, v := range d.Shape { for _, v := range d.Shape {

View File

@ -179,6 +179,7 @@ func (rows *Rows) Columns(opts ...Options) ([]string, error) {
return rowIterator.columns, rowIterator.err return rowIterator.columns, rowIterator.err
} }
// extractRowOpts extract row element attributes.
func extractRowOpts(attrs []xml.Attr) RowOpts { func extractRowOpts(attrs []xml.Attr) RowOpts {
rowOpts := RowOpts{Height: defaultRowHeight} rowOpts := RowOpts{Height: defaultRowHeight}
if styleID, err := attrValToInt("s", attrs); err == nil && styleID > 0 && styleID < MaxCellStyles { if styleID, err := attrValToInt("s", attrs); err == nil && styleID > 0 && styleID < MaxCellStyles {