15 const M_2DIVPI = 0.63661977236758134307553505349006;
49 'divisionbyzero' =>
'#DIV/0!',
51 'reference' =>
'#REF!',
55 'gettingdata' =>
'#GETTING_DATA',
95 return self::$compatibilityMode;
135 return self::$returnDateType;
145 return '#Not Yet Implemented';
155 return self::$errorCodes[
'divisionbyzero'];
169 public static function NA()
171 return self::$errorCodes[
'na'];
181 public static function NAN()
183 return self::$errorCodes[
'num'];
195 return self::$errorCodes[
'name'];
205 public static function REF()
207 return self::$errorCodes[
'reference'];
219 return self::$errorCodes[
'null'];
231 return self::$errorCodes[
'value'];
236 return (substr_count($idx,
'.') <= 1) || (preg_match(
'/\.[A-Z]/', $idx) > 0);
241 return substr_count($idx,
'.') == 0;
246 return substr_count($idx,
'.') > 1;
251 $condition = self::flattenSingleValue($condition);
253 if ($condition ===
'') {
256 if (!is_string($condition) || !in_array($condition[0], [
'>',
'<',
'='])) {
257 $condition = self::operandSpecialHandling($condition);
258 if (is_bool($condition)) {
259 return '=' . ($condition ?
'TRUE' :
'FALSE');
260 } elseif (!is_numeric($condition)) {
264 return str_replace(
'""""',
'""',
'=' . $condition);
266 preg_match(
'/(=|<[>=]?|>=?)(.*)/', $condition, $matches);
267 [, $operator, $operand] = $matches;
269 $operand = self::operandSpecialHandling($operand);
270 if (is_numeric(trim($operand,
'"'))) {
271 $operand = trim($operand,
'"');
272 } elseif (!is_numeric($operand) && $operand !==
'FALSE' && $operand !==
'TRUE') {
273 $operand = str_replace(
'"',
'""', $operand);
277 return str_replace(
'""""',
'""', $operator . $operand);
282 if (is_numeric($operand) || is_bool($operand)) {
285 return strtoupper($operand);
289 if (preg_match(
'/^\-?\d*\.?\d*\s?\%$/', $operand)) {
290 return ((
float) rtrim($operand,
'%')) / 100;
294 if (($dateValueOperand = Date::stringToExcel($operand)) !==
false) {
295 return $dateValueOperand;
310 $value = self::flattenSingleValue($value);
314 if ($value === $errorCode) {
332 if ($value !==
null) {
333 $value = self::flattenSingleValue($value);
336 return $value ===
null;
346 public static function isErr($value =
'')
348 $value = self::flattenSingleValue($value);
350 return self::isError($value) && (!self::isNa(($value)));
362 $value = self::flattenSingleValue($value);
364 if (!is_string($value)) {
368 return in_array($value, self::$errorCodes);
378 public static function isNa($value =
'')
380 $value = self::flattenSingleValue($value);
382 return $value === self::NA();
394 $value = self::flattenSingleValue($value);
396 if ($value ===
null) {
398 } elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
399 return self::VALUE();
402 return $value % 2 == 0;
414 $value = self::flattenSingleValue($value);
416 if ($value ===
null) {
418 } elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) {
419 return self::VALUE();
422 return abs($value) % 2 == 1;
434 $value = self::flattenSingleValue($value);
436 if (is_string($value)) {
440 return is_numeric($value);
452 $value = self::flattenSingleValue($value);
454 return is_bool($value);
466 $value = self::flattenSingleValue($value);
468 return is_string($value) && !self::isError($value);
480 return !self::isText($value);
499 public static function n($value =
null)
501 while (is_array($value)) {
502 $value = array_shift($value);
505 switch (gettype($value)) {
514 if ((strlen($value) > 0) && ($value[0] ==
'#')) {
541 $value = self::flattenArrayIndexed($value);
542 if (is_array($value) && (count($value) > 1)) {
546 if (self::isCellValue($a)) {
549 } elseif (self::isMatrixValue($a)) {
552 } elseif (empty($value)) {
556 $value = self::flattenSingleValue($value);
558 if (($value ===
null) || (is_float($value)) || (is_int($value))) {
560 } elseif (is_bool($value)) {
562 } elseif (is_array($value)) {
564 } elseif (is_string($value)) {
566 if ((strlen($value) > 0) && ($value[0] ==
'#')) {
585 if (!is_array($array)) {
586 return (array) $array;
590 foreach ($array as $value) {
591 if (is_array($value)) {
592 foreach ($value as $val) {
593 if (is_array($val)) {
594 foreach ($val as $v) {
598 $arrayValues[] = $val;
602 $arrayValues[] = $value;
618 if (!is_array($array)) {
619 return (array) $array;
623 foreach ($array as $k1 => $value) {
624 if (is_array($value)) {
625 foreach ($value as $k2 => $val) {
626 if (is_array($val)) {
627 foreach ($val as $k3 => $v) {
628 $arrayValues[$k1 .
'.' . $k2 .
'.' . $k3] = $v;
631 $arrayValues[$k1 .
'.' . $k2] = $val;
635 $arrayValues[$k1] = $value;
651 while (is_array($value)) {
652 $value = array_shift($value);
668 if ($pCell ===
null) {
674 $cellReference = $matches[6] . $matches[7];
675 $worksheetName = str_replace(
"''",
"'", trim($matches[2],
"'"));
677 $worksheet = (!empty($worksheetName))
678 ? $pCell->getWorksheet()->getParent()->getSheetByName($worksheetName)
679 : $pCell->getWorksheet();
681 return $worksheet->getCell($cellReference)->isFormula();
static isNumber($value=null)
IS_NUMBER.
static isFormula($cellReference='', ?Cell $pCell=null)
ISFORMULA.
static isEven($value=null)
IS_EVEN.
static getReturnDateType()
Return the current Return Date Format for functions that return a date/time (Excel, PHP Serialized Numeric or PHP Object).
static $compatibilityMode
static wrapResult($value)
Wrap string values in quotes.
static ifCondition($condition)
static isBlank($value=null)
IS_BLANK.
static isErr($value='')
IS_ERR.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
const RETURNDATE_PHP_NUMERIC
static isMatrixValue($idx)
static errorType($value='')
ERROR_TYPE.
static isOdd($value=null)
IS_ODD.
static isLogical($value=null)
IS_LOGICAL.
static static setCompatibilityMode($compatibilityMode)
Set the Compatibility Mode.
static operandSpecialHandling($operand)
const COMPATIBILITY_EXCEL
constants
static setReturnDateType($returnDateType)
Set the Return Date Format used by functions that return a date/time (Excel, PHP Serialized Numeric o...
const RETURNDATE_UNIX_TIMESTAMP
static isError($value='')
IS_ERROR.
static getFALSE()
Return the locale-specific translation of FALSE.
static flattenArrayIndexed($array)
Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing...
const COMPATIBILITY_OPENOFFICE
static getTRUE()
Return the locale-specific translation of TRUE.
const COMPATIBILITY_GNUMERIC
const CALCULATION_REGEXP_CELLREF
const RETURNDATE_PHP_DATETIME_OBJECT
static TYPE($value=null)
TYPE.
const RETURNDATE_PHP_OBJECT
static isText($value=null)
IS_TEXT.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static isNonText($value=null)
IS_NONTEXT.
static isNa($value='')
IS_NA.
static getCompatibilityMode()
Return the current Compatibility Mode.