-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
This is:
- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)
What is the expected behavior?
COUNTIF() should properly parse comparison expressions in the selection criteria parameter.
What is the current behavior?
PhpSpreadsheet is generating the error Formula Error: Unexpected operator '<'
when it tries to evaluate the function:
COUNTIF(F12,"<>< Please Select >")
The underlying issue is that method Calculations\Functions::ifCondition()
is not properly parsing the conditional operator in the front of the selection parameter. For example, it thinks that the selection parameter above means:
<>< "PLEASE SELECT >"
when it should mean
<> "< PLEASE SELECT >"
This problem is due to an overly aggressive regular expression that matches any length of '<', '>', and '=' characters, when it should be limited to just '=', '<', '>', '<>', '<=', or '>=', (see section 18.17.2.2 in ECMA 376 5th Edition Part 1 for all allowable comparison operators in Open Office Spreadsheet XML formulas.)
Other statistical functions that use ifCondition() also probably suffer from this issue. The MAXIF(), MINIF(), and AVERAGEIF() functions use ifCondition() as well.
What are the steps to reproduce?
Calling Calculations\Functions::ifCondition()
on formula COUNTIF(F12,"<>< Please Select >")
will generate an exception with message Formula Error: Unexpected operator '<'
Which versions of PhpSpreadsheet and PHP are affected?
This occurs in 1.2.1 of PhpSpreadsheet. I haven't checked earlier versions. I did not see this in PhpExcel.