forked from p30928647/excelize
This fixed #1564, apply all of its arguments that meet multiple criteria
This commit is contained in:
parent
dcb26b2cb8
commit
700af6a529
6
calc.go
6
calc.go
|
@ -7812,6 +7812,7 @@ func formulaIfsMatch(args []formulaArg) (cellRefs []cellRef) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
match = []cellRef{}
|
||||
for _, ref := range cellRefs {
|
||||
value := matrix[ref.Row][ref.Col]
|
||||
if ok, _ := formulaCriteriaEval(value.Value(), criteria); ok {
|
||||
|
@ -7819,9 +7820,6 @@ func formulaIfsMatch(args []formulaArg) (cellRefs []cellRef) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if len(match) == 0 {
|
||||
return
|
||||
}
|
||||
cellRefs = match[:]
|
||||
}
|
||||
return
|
||||
|
@ -14397,7 +14395,7 @@ func (fn *formulaFuncs) MATCH(argsList *list.List) formulaArg {
|
|||
}
|
||||
switch lookupArrayArg.Type {
|
||||
case ArgMatrix:
|
||||
if len(lookupArrayArg.Matrix[0]) != 1 {
|
||||
if len(lookupArrayArg.Matrix) != 1 && len(lookupArrayArg.Matrix[0]) != 1 {
|
||||
return newErrorFormulaArg(formulaErrorNA, lookupArrayErr)
|
||||
}
|
||||
lookupArray = lookupArrayArg.ToList()
|
||||
|
|
16
calc_test.go
16
calc_test.go
|
@ -3828,7 +3828,8 @@ func TestCalcCellValue(t *testing.T) {
|
|||
"=MATCH(0,A1:A1,0,0)": {"#VALUE!", "MATCH requires 1 or 2 arguments"},
|
||||
"=MATCH(0,A1:A1,\"x\")": {"#VALUE!", "MATCH requires numeric match_type argument"},
|
||||
"=MATCH(0,A1)": {"#N/A", "MATCH arguments lookup_array should be one-dimensional array"},
|
||||
"=MATCH(0,A1:B1)": {"#N/A", "MATCH arguments lookup_array should be one-dimensional array"},
|
||||
"=MATCH(0,A1:B2)": {"#N/A", "MATCH arguments lookup_array should be one-dimensional array"},
|
||||
"=MATCH(0,A1:B1)": {"#N/A", "#N/A"},
|
||||
// TRANSPOSE
|
||||
"=TRANSPOSE()": {"#VALUE!", "TRANSPOSE requires 1 argument"},
|
||||
// HYPERLINK
|
||||
|
@ -5131,10 +5132,14 @@ func TestCalcSUMIFSAndAVERAGEIFS(t *testing.T) {
|
|||
}
|
||||
f := prepareCalcData(cellData)
|
||||
formulaList := map[string]string{
|
||||
"=AVERAGEIFS(D2:D13,A2:A13,1,B2:B13,\"North\")": "174000",
|
||||
"=AVERAGEIFS(D2:D13,A2:A13,\">2\",C2:C13,\"Jeff\")": "285500",
|
||||
"=SUMIFS(D2:D13,A2:A13,1,B2:B13,\"North\")": "348000",
|
||||
"=SUMIFS(D2:D13,A2:A13,\">2\",C2:C13,\"Jeff\")": "571000",
|
||||
"=AVERAGEIFS(D2:D13,A2:A13,1,B2:B13,\"North\")": "174000",
|
||||
"=AVERAGEIFS(D2:D13,A2:A13,\">2\",C2:C13,\"Jeff\")": "285500",
|
||||
"=SUMIFS(D2:D13,A2:A13,1,B2:B13,\"North\")": "348000",
|
||||
"=SUMIFS(D2:D13,A2:A13,\">2\",C2:C13,\"Jeff\")": "571000",
|
||||
"=SUMIFS(D2:D13,A2:A13,1,D2:D13,125000)": "125000",
|
||||
"=SUMIFS(D2:D13,A2:A13,1,D2:D13,\">100000\",C2:C13,\"Chris\")": "125000",
|
||||
"=SUMIFS(D2:D13,A2:A13,1,D2:D13,\"<40000\",C2:C13,\"Chris\")": "0",
|
||||
"=SUMIFS(D2:D13,A2:A13,1,A2:A13,2)": "0",
|
||||
}
|
||||
for formula, expected := range formulaList {
|
||||
assert.NoError(t, f.SetCellFormula("Sheet1", "E1", formula))
|
||||
|
@ -5147,6 +5152,7 @@ func TestCalcSUMIFSAndAVERAGEIFS(t *testing.T) {
|
|||
"=AVERAGEIFS(H1,\"\")": {"#VALUE!", "AVERAGEIFS requires at least 3 arguments"},
|
||||
"=AVERAGEIFS(H1,\"\",TRUE,1)": {"#N/A", "#N/A"},
|
||||
"=AVERAGEIFS(H1,\"\",TRUE)": {"#DIV/0!", "AVERAGEIF divide by zero"},
|
||||
"=AVERAGEIFS(D2:D13,A2:A13,1,A2:A13,2)": {"#DIV/0!", "AVERAGEIF divide by zero"},
|
||||
"=SUMIFS()": {"#VALUE!", "SUMIFS requires at least 3 arguments"},
|
||||
"=SUMIFS(D2:D13,A2:A13,1,B2:B13)": {"#N/A", "#N/A"},
|
||||
"=SUMIFS(D20:D23,A2:A13,\">2\",C2:C13,\"Jeff\")": {"#VALUE!", "#VALUE!"},
|
||||
|
|
Loading…
Reference in New Issue