More PSR-2 adjustments

This commit is contained in:
MarkBaker 2015-05-10 23:25:04 +01:00
parent c07b54172a
commit 1efa7e8533
5 changed files with 1364 additions and 1223 deletions

View File

@ -1,6 +1,16 @@
<?php <?php
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/** /**
* PHPExcel * @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_LookupRef
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,28 +34,8 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_Calculation_LookupRef
{
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_LookupRef
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_LookupRef {
/** /**
* CELL_ADDRESS * CELL_ADDRESS
* *
@ -67,7 +57,8 @@ class PHPExcel_Calculation_LookupRef {
* @param sheetText Optional Name of worksheet to use * @param sheetText Optional Name of worksheet to use
* @return string * @return string
*/ */
public static function CELL_ADDRESS($row, $column, $relativity=1, $referenceStyle=True, $sheetText='') { public static function CELL_ADDRESS($row, $column, $relativity = 1, $referenceStyle = true, $sheetText = '')
{
$row = PHPExcel_Calculation_Functions::flattenSingleValue($row); $row = PHPExcel_Calculation_Functions::flattenSingleValue($row);
$column = PHPExcel_Calculation_Functions::flattenSingleValue($column); $column = PHPExcel_Calculation_Functions::flattenSingleValue($column);
$relativity = PHPExcel_Calculation_Functions::flattenSingleValue($relativity); $relativity = PHPExcel_Calculation_Functions::flattenSingleValue($relativity);
@ -78,21 +69,31 @@ class PHPExcel_Calculation_LookupRef {
} }
if ($sheetText > '') { if ($sheetText > '') {
if (strpos($sheetText,' ') !== False) { $sheetText = "'".$sheetText."'"; } if (strpos($sheetText, ' ') !== false) {
$sheetText = "'".$sheetText."'";
}
$sheetText .='!'; $sheetText .='!';
} }
if ((!is_bool($referenceStyle)) || $referenceStyle) { if ((!is_bool($referenceStyle)) || $referenceStyle) {
$rowRelative = $columnRelative = '$'; $rowRelative = $columnRelative = '$';
$column = PHPExcel_Cell::stringFromColumnIndex($column-1); $column = PHPExcel_Cell::stringFromColumnIndex($column-1);
if (($relativity == 2) || ($relativity == 4)) { $columnRelative = ''; } if (($relativity == 2) || ($relativity == 4)) {
if (($relativity == 3) || ($relativity == 4)) { $rowRelative = ''; } $columnRelative = '';
}
if (($relativity == 3) || ($relativity == 4)) {
$rowRelative = '';
}
return $sheetText.$columnRelative.$column.$rowRelative.$row; return $sheetText.$columnRelative.$column.$rowRelative.$row;
} else { } else {
if (($relativity == 2) || ($relativity == 4)) { $column = '['.$column.']'; } if (($relativity == 2) || ($relativity == 4)) {
if (($relativity == 3) || ($relativity == 4)) { $row = '['.$row.']'; } $column = '['.$column.']';
}
if (($relativity == 3) || ($relativity == 4)) {
$row = '['.$row.']';
}
return $sheetText.'R'.$row.'C'.$column; return $sheetText.'R'.$row.'C'.$column;
} }
} // function CELL_ADDRESS() }
/** /**
@ -109,8 +110,11 @@ class PHPExcel_Calculation_LookupRef {
* @param cellAddress A reference to a range of cells for which you want the column numbers * @param cellAddress A reference to a range of cells for which you want the column numbers
* @return integer or array of integer * @return integer or array of integer
*/ */
public static function COLUMN($cellAddress=Null) { public static function COLUMN($cellAddress = null)
if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; } {
if (is_null($cellAddress) || trim($cellAddress) === '') {
return 0;
}
if (is_array($cellAddress)) { if (is_array($cellAddress)) {
foreach ($cellAddress as $columnKey => $value) { foreach ($cellAddress as $columnKey => $value) {
@ -135,7 +139,7 @@ class PHPExcel_Calculation_LookupRef {
return (integer) PHPExcel_Cell::columnIndexFromString($cellAddress); return (integer) PHPExcel_Cell::columnIndexFromString($cellAddress);
} }
} }
} // function COLUMN() }
/** /**
@ -149,7 +153,8 @@ class PHPExcel_Calculation_LookupRef {
* @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of columns * @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of columns
* @return integer The number of columns in cellAddress * @return integer The number of columns in cellAddress
*/ */
public static function COLUMNS($cellAddress = null) { public static function COLUMNS($cellAddress = null)
{
if (is_null($cellAddress) || $cellAddress === '') { if (is_null($cellAddress) || $cellAddress === '') {
return 1; return 1;
} elseif (!is_array($cellAddress)) { } elseif (!is_array($cellAddress)) {
@ -165,7 +170,7 @@ class PHPExcel_Calculation_LookupRef {
} else { } else {
return $columns; return $columns;
} }
} // function COLUMNS() }
/** /**
@ -182,8 +187,11 @@ class PHPExcel_Calculation_LookupRef {
* @param cellAddress A reference to a range of cells for which you want the row numbers * @param cellAddress A reference to a range of cells for which you want the row numbers
* @return integer or array of integer * @return integer or array of integer
*/ */
public static function ROW($cellAddress=Null) { public static function ROW($cellAddress = null)
if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; } {
if (is_null($cellAddress) || trim($cellAddress) === '') {
return 0;
}
if (is_array($cellAddress)) { if (is_array($cellAddress)) {
foreach ($cellAddress as $columnKey => $rowValue) { foreach ($cellAddress as $columnKey => $rowValue) {
@ -209,7 +217,7 @@ class PHPExcel_Calculation_LookupRef {
return (integer) preg_replace('/[^0-9]/', '', $cellAddress); return (integer) preg_replace('/[^0-9]/', '', $cellAddress);
} }
} }
} // function ROW() }
/** /**
@ -223,7 +231,8 @@ class PHPExcel_Calculation_LookupRef {
* @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of rows * @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of rows
* @return integer The number of rows in cellAddress * @return integer The number of rows in cellAddress
*/ */
public static function ROWS($cellAddress=Null) { public static function ROWS($cellAddress = null)
{
if (is_null($cellAddress) || $cellAddress === '') { if (is_null($cellAddress) || $cellAddress === '') {
return 1; return 1;
} elseif (!is_array($cellAddress)) { } elseif (!is_array($cellAddress)) {
@ -239,7 +248,7 @@ class PHPExcel_Calculation_LookupRef {
} else { } else {
return $rows; return $rows;
} }
} // function ROWS() }
/** /**
@ -255,7 +264,8 @@ class PHPExcel_Calculation_LookupRef {
* @param PHPExcel_Cell $pCell The cell to set the hyperlink in * @param PHPExcel_Cell $pCell The cell to set the hyperlink in
* @return mixed The value of $displayName (or $linkURL if $displayName was blank) * @return mixed The value of $displayName (or $linkURL if $displayName was blank)
*/ */
public static function HYPERLINK($linkURL = '', $displayName = null, PHPExcel_Cell $pCell = null) { public static function HYPERLINK($linkURL = '', $displayName = null, PHPExcel_Cell $pCell = null)
{
$args = func_get_args(); $args = func_get_args();
$pCell = array_pop($args); $pCell = array_pop($args);
@ -273,7 +283,7 @@ class PHPExcel_Calculation_LookupRef {
$pCell->getHyperlink()->setUrl($linkURL); $pCell->getHyperlink()->setUrl($linkURL);
return $displayName; return $displayName;
} // function HYPERLINK() }
/** /**
@ -294,14 +304,15 @@ class PHPExcel_Calculation_LookupRef {
* @todo Support for the optional a1 parameter introduced in Excel 2010 * @todo Support for the optional a1 parameter introduced in Excel 2010
* *
*/ */
public static function INDIRECT($cellAddress = NULL, PHPExcel_Cell $pCell = NULL) { public static function INDIRECT($cellAddress = null, PHPExcel_Cell $pCell = null)
{
$cellAddress = PHPExcel_Calculation_Functions::flattenSingleValue($cellAddress); $cellAddress = PHPExcel_Calculation_Functions::flattenSingleValue($cellAddress);
if (is_null($cellAddress) || $cellAddress === '') { if (is_null($cellAddress) || $cellAddress === '') {
return PHPExcel_Calculation_Functions::REF(); return PHPExcel_Calculation_Functions::REF();
} }
$cellAddress1 = $cellAddress; $cellAddress1 = $cellAddress;
$cellAddress2 = NULL; $cellAddress2 = null;
if (strpos($cellAddress, ':') !== false) { if (strpos($cellAddress, ':') !== false) {
list($cellAddress1, $cellAddress2) = explode(':', $cellAddress); list($cellAddress1, $cellAddress2) = explode(':', $cellAddress);
} }
@ -312,7 +323,7 @@ class PHPExcel_Calculation_LookupRef {
return PHPExcel_Calculation_Functions::REF(); return PHPExcel_Calculation_Functions::REF();
} }
if (strpos($cellAddress,'!') !== FALSE) { if (strpos($cellAddress, '!') !== false) {
list($sheetName, $cellAddress) = explode('!', $cellAddress); list($sheetName, $cellAddress) = explode('!', $cellAddress);
$sheetName = trim($sheetName, "'"); $sheetName = trim($sheetName, "'");
$pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName); $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
@ -320,10 +331,10 @@ class PHPExcel_Calculation_LookupRef {
$pSheet = $pCell->getWorksheet(); $pSheet = $pCell->getWorksheet();
} }
return PHPExcel_Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, FALSE); return PHPExcel_Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, false);
} }
if (strpos($cellAddress,'!') !== FALSE) { if (strpos($cellAddress, '!') !== false) {
list($sheetName, $cellAddress) = explode('!', $cellAddress); list($sheetName, $cellAddress) = explode('!', $cellAddress);
$sheetName = trim($sheetName, "'"); $sheetName = trim($sheetName, "'");
$pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName); $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
@ -331,8 +342,8 @@ class PHPExcel_Calculation_LookupRef {
$pSheet = $pCell->getWorksheet(); $pSheet = $pCell->getWorksheet();
} }
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, FALSE); return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false);
} // function INDIRECT() }
/** /**
@ -360,12 +371,13 @@ class PHPExcel_Calculation_LookupRef {
* @param width The width, in number of columns, that you want the returned reference to be. Width must be a positive number. * @param width The width, in number of columns, that you want the returned reference to be. Width must be a positive number.
* @return string A reference to a cell or range of cells * @return string A reference to a cell or range of cells
*/ */
public static function OFFSET($cellAddress=Null,$rows=0,$columns=0,$height=null,$width=null) { public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null)
{
$rows = PHPExcel_Calculation_Functions::flattenSingleValue($rows); $rows = PHPExcel_Calculation_Functions::flattenSingleValue($rows);
$columns = PHPExcel_Calculation_Functions::flattenSingleValue($columns); $columns = PHPExcel_Calculation_Functions::flattenSingleValue($columns);
$height = PHPExcel_Calculation_Functions::flattenSingleValue($height); $height = PHPExcel_Calculation_Functions::flattenSingleValue($height);
$width = PHPExcel_Calculation_Functions::flattenSingleValue($width); $width = PHPExcel_Calculation_Functions::flattenSingleValue($width);
if ($cellAddress == Null) { if ($cellAddress == null) {
return 0; return 0;
} }
@ -375,7 +387,7 @@ class PHPExcel_Calculation_LookupRef {
return PHPExcel_Calculation_Functions::REF(); return PHPExcel_Calculation_Functions::REF();
} }
$sheetName = NULL; $sheetName = null;
if (strpos($cellAddress, "!")) { if (strpos($cellAddress, "!")) {
list($sheetName, $cellAddress) = explode("!", $cellAddress); list($sheetName, $cellAddress) = explode("!", $cellAddress);
$sheetName = trim($sheetName, "'"); $sheetName = trim($sheetName, "'");
@ -419,14 +431,14 @@ class PHPExcel_Calculation_LookupRef {
$cellAddress .= ':'.$endCellColumn.$endCellRow; $cellAddress .= ':'.$endCellColumn.$endCellRow;
} }
if ($sheetName !== NULL) { if ($sheetName !== null) {
$pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName); $pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
} else { } else {
$pSheet = $pCell->getWorksheet(); $pSheet = $pCell->getWorksheet();
} }
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False); return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false);
} // function OFFSET() }
/** /**
@ -447,7 +459,8 @@ class PHPExcel_Calculation_LookupRef {
* text. * text.
* @return mixed The selected value * @return mixed The selected value
*/ */
public static function CHOOSE() { public static function CHOOSE()
{
$chooseArgs = func_get_args(); $chooseArgs = func_get_args();
$chosenEntry = PHPExcel_Calculation_Functions::flattenArray(array_shift($chooseArgs)); $chosenEntry = PHPExcel_Calculation_Functions::flattenArray(array_shift($chooseArgs));
$entryCount = count($chooseArgs) - 1; $entryCount = count($chooseArgs) - 1;
@ -470,7 +483,7 @@ class PHPExcel_Calculation_LookupRef {
} else { } else {
return $chooseArgs[$chosenEntry]; return $chooseArgs[$chosenEntry];
} }
} // function CHOOSE() }
/** /**
@ -486,7 +499,8 @@ class PHPExcel_Calculation_LookupRef {
* @param match_type The number -1, 0, or 1. -1 means above, 0 means exact match, 1 means below. If match_type is 1 or -1, the list has to be ordered. * @param match_type The number -1, 0, or 1. -1 means above, 0 means exact match, 1 means below. If match_type is 1 or -1, the list has to be ordered.
* @return integer The relative position of the found item * @return integer The relative position of the found item
*/ */
public static function MATCH($lookup_value, $lookup_array, $match_type=1) { public static function MATCH($lookup_value, $lookup_array, $match_type = 1)
{
$lookup_array = PHPExcel_Calculation_Functions::flattenArray($lookup_array); $lookup_array = PHPExcel_Calculation_Functions::flattenArray($lookup_array);
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); $lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
$match_type = (is_null($match_type)) ? 1 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($match_type); $match_type = (is_null($match_type)) ? 1 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($match_type);
@ -537,42 +551,25 @@ class PHPExcel_Calculation_LookupRef {
// ** // **
// find the match // find the match
// ** // **
// loop on the cells
// var_dump($lookup_array);
// echo '<br />';
foreach ($lookup_array as $i => $lookupArrayValue) { foreach ($lookup_array as $i => $lookupArrayValue) {
if (($match_type == 0) && ($lookupArrayValue == $lookup_value)) { if (($match_type == 0) && ($lookupArrayValue == $lookup_value)) {
// exact match // exact match
return ++$i; return ++$i;
} elseif (($match_type == -1) && ($lookupArrayValue <= $lookup_value)) { } elseif (($match_type == -1) && ($lookupArrayValue <= $lookup_value)) {
// echo '$i = '.$i.' => ';
// var_dump($lookupArrayValue);
// echo '<br />';
// echo 'Keyset = ';
// var_dump($keySet);
// echo '<br />';
$i = array_search($i, $keySet); $i = array_search($i, $keySet);
// echo '$i='.$i.'<br />';
// if match_type is -1 <=> find the smallest value that is greater than or equal to lookup_value // if match_type is -1 <=> find the smallest value that is greater than or equal to lookup_value
if ($i < 1) { if ($i < 1) {
// 1st cell was allready smaller than the lookup_value // 1st cell was already smaller than the lookup_value
break; break;
} else { } else {
// the previous cell was the match // the previous cell was the match
return $keySet[$i-1]+1; return $keySet[$i-1]+1;
} }
} elseif (($match_type == 1) && ($lookupArrayValue >= $lookup_value)) { } elseif (($match_type == 1) && ($lookupArrayValue >= $lookup_value)) {
// echo '$i = '.$i.' => ';
// var_dump($lookupArrayValue);
// echo '<br />';
// echo 'Keyset = ';
// var_dump($keySet);
// echo '<br />';
$i = array_search($i, $keySet); $i = array_search($i, $keySet);
// echo '$i='.$i.'<br />';
// if match_type is 1 <=> find the largest value that is less than or equal to lookup_value // if match_type is 1 <=> find the largest value that is less than or equal to lookup_value
if ($i < 1) { if ($i < 1) {
// 1st cell was allready bigger than the lookup_value // 1st cell was already bigger than the lookup_value
break; break;
} else { } else {
// the previous cell was the match // the previous cell was the match
@ -583,7 +580,7 @@ class PHPExcel_Calculation_LookupRef {
// unsuccessful in finding a match, return #N/A error value // unsuccessful in finding a match, return #N/A error value
return PHPExcel_Calculation_Functions::NA(); return PHPExcel_Calculation_Functions::NA();
} // function MATCH() }
/** /**
@ -599,8 +596,8 @@ class PHPExcel_Calculation_LookupRef {
* @param column_num The column in array from which to return a value. If column_num is omitted, row_num is required. * @param column_num The column in array from which to return a value. If column_num is omitted, row_num is required.
* @return mixed the value of a specified cell or array of cells * @return mixed the value of a specified cell or array of cells
*/ */
public static function INDEX($arrayValues,$rowNum = 0,$columnNum = 0) { public static function INDEX($arrayValues, $rowNum = 0, $columnNum = 0)
{
if (($rowNum < 0) || ($columnNum < 0)) { if (($rowNum < 0) || ($columnNum < 0)) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
@ -642,7 +639,7 @@ class PHPExcel_Calculation_LookupRef {
$rowNum = $rowKeys[--$rowNum]; $rowNum = $rowKeys[--$rowNum];
return $arrayValues[$rowNum][$columnNum]; return $arrayValues[$rowNum][$columnNum];
} // function INDEX() }
/** /**
@ -653,9 +650,12 @@ class PHPExcel_Calculation_LookupRef {
* *
* Unlike the Excel TRANSPOSE function, which will only work on a single row or column, this function will transpose a full matrix. * Unlike the Excel TRANSPOSE function, which will only work on a single row or column, this function will transpose a full matrix.
*/ */
public static function TRANSPOSE($matrixData) { public static function TRANSPOSE($matrixData)
{
$returnMatrix = array(); $returnMatrix = array();
if (!is_array($matrixData)) { $matrixData = array(array($matrixData)); } if (!is_array($matrixData)) {
$matrixData = array(array($matrixData));
}
$column = 0; $column = 0;
foreach ($matrixData as $matrixRow) { foreach ($matrixData as $matrixRow) {
@ -667,17 +667,18 @@ class PHPExcel_Calculation_LookupRef {
++$column; ++$column;
} }
return $returnMatrix; return $returnMatrix;
} // function TRANSPOSE() }
private static function _vlookupSort($a,$b) { private static function vlookupSort($a, $b)
{
reset($a); reset($a);
$firstColumn = key($a); $firstColumn = key($a);
if (strtolower($a[$firstColumn]) == strtolower($b[$firstColumn])) { if (strtolower($a[$firstColumn]) == strtolower($b[$firstColumn])) {
return 0; return 0;
} }
return (strtolower($a[$firstColumn]) < strtolower($b[$firstColumn])) ? -1 : 1; return (strtolower($a[$firstColumn]) < strtolower($b[$firstColumn])) ? -1 : 1;
} // function _vlookupSort() }
/** /**
@ -689,7 +690,8 @@ class PHPExcel_Calculation_LookupRef {
* @param not_exact_match Determines if you are looking for an exact match based on lookup_value. * @param not_exact_match Determines if you are looking for an exact match based on lookup_value.
* @return mixed The value of the found cell * @return mixed The value of the found cell
*/ */
public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match=true) { public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true)
{
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); $lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
$index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number); $index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number);
$not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match); $not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match);
@ -715,10 +717,10 @@ class PHPExcel_Calculation_LookupRef {
} }
if (!$not_exact_match) { if (!$not_exact_match) {
uasort($lookup_array,array('self','_vlookupSort')); uasort($lookup_array, array('self', 'vlookupSort'));
} }
$rowNumber = $rowValue = False; $rowNumber = $rowValue = false;
foreach ($lookup_array as $rowKey => $rowData) { foreach ($lookup_array as $rowKey => $rowData) {
if ((is_numeric($lookup_value) && is_numeric($rowData[$firstColumn]) && ($rowData[$firstColumn] > $lookup_value)) || if ((is_numeric($lookup_value) && is_numeric($rowData[$firstColumn]) && ($rowData[$firstColumn] > $lookup_value)) ||
(!is_numeric($lookup_value) && !is_numeric($rowData[$firstColumn]) && (strtolower($rowData[$firstColumn]) > strtolower($lookup_value)))) { (!is_numeric($lookup_value) && !is_numeric($rowData[$firstColumn]) && (strtolower($rowData[$firstColumn]) > strtolower($lookup_value)))) {
@ -739,7 +741,7 @@ class PHPExcel_Calculation_LookupRef {
} }
return PHPExcel_Calculation_Functions::NA(); return PHPExcel_Calculation_Functions::NA();
} // function VLOOKUP() }
/** /**
@ -751,7 +753,8 @@ class PHPExcel_Calculation_LookupRef {
* @param not_exact_match Determines if you are looking for an exact match based on lookup_value. * @param not_exact_match Determines if you are looking for an exact match based on lookup_value.
* @return mixed The value of the found cell * @return mixed The value of the found cell
*/ */
public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match=true) { public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true)
{
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); $lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
$index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number); $index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number);
$not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match); $not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match);
@ -781,7 +784,7 @@ class PHPExcel_Calculation_LookupRef {
$firstRowH = asort($lookup_array[$firstColumn]); $firstRowH = asort($lookup_array[$firstColumn]);
} }
$rowNumber = $rowValue = False; $rowNumber = $rowValue = false;
foreach ($lookup_array[$firstColumn] as $rowKey => $rowData) { foreach ($lookup_array[$firstColumn] as $rowKey => $rowData) {
if ((is_numeric($lookup_value) && is_numeric($rowData) && ($rowData > $lookup_value)) || if ((is_numeric($lookup_value) && is_numeric($rowData) && ($rowData > $lookup_value)) ||
(!is_numeric($lookup_value) && !is_numeric($rowData) && (strtolower($rowData) > strtolower($lookup_value)))) { (!is_numeric($lookup_value) && !is_numeric($rowData) && (strtolower($rowData) > strtolower($lookup_value)))) {
@ -802,7 +805,7 @@ class PHPExcel_Calculation_LookupRef {
} }
return PHPExcel_Calculation_Functions::NA(); return PHPExcel_Calculation_Functions::NA();
} // function HLOOKUP() }
/** /**
@ -813,7 +816,8 @@ class PHPExcel_Calculation_LookupRef {
* @param result_vector The column from which the matching value must be returned * @param result_vector The column from which the matching value must be returned
* @return mixed The value of the found cell * @return mixed The value of the found cell
*/ */
public static function LOOKUP($lookup_value, $lookup_vector, $result_vector=null) { public static function LOOKUP($lookup_value, $lookup_vector, $result_vector = null)
{
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value); $lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
if (!is_array($lookup_vector)) { if (!is_array($lookup_vector)) {
@ -870,6 +874,5 @@ class PHPExcel_Calculation_LookupRef {
} }
return self::VLOOKUP($lookup_value, $lookup_vector, 2); return self::VLOOKUP($lookup_value, $lookup_vector, 2);
} // function LOOKUP() }
}
} // class PHPExcel_Calculation_LookupRef

View File

@ -1,6 +1,16 @@
<?php <?php
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/** /**
* PHPExcel * @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_MathTrig
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,38 +34,20 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_Calculation_MathTrig
{
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_MathTrig
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_MathTrig {
// //
// Private method to return an array of the factors of the input value // Private method to return an array of the factors of the input value
// //
private static function _factors($value) { private static function factors($value)
{
$startVal = floor(sqrt($value)); $startVal = floor(sqrt($value));
$factorArray = array(); $factorArray = array();
for ($i = $startVal; $i > 1; --$i) { for ($i = $startVal; $i > 1; --$i) {
if (($value % $i) == 0) { if (($value % $i) == 0) {
$factorArray = array_merge($factorArray,self::_factors($value / $i)); $factorArray = array_merge($factorArray, self::factors($value / $i));
$factorArray = array_merge($factorArray,self::_factors($i)); $factorArray = array_merge($factorArray, self::factors($i));
if ($i <= sqrt($value)) { if ($i <= sqrt($value)) {
break; break;
} }
@ -67,12 +59,13 @@ class PHPExcel_Calculation_MathTrig {
} else { } else {
return array((integer) $value); return array((integer) $value);
} }
} // function _factors() }
private static function _romanCut($num, $n) { private static function romanCut($num, $n)
{
return ($num - ($num % $n ) ) / $n; return ($num - ($num % $n ) ) / $n;
} // function _romanCut() }
/** /**
@ -97,12 +90,13 @@ class PHPExcel_Calculation_MathTrig {
* @param float $yCoordinate The y-coordinate of the point. * @param float $yCoordinate The y-coordinate of the point.
* @return float The inverse tangent of the specified x- and y-coordinates. * @return float The inverse tangent of the specified x- and y-coordinates.
*/ */
public static function ATAN2($xCoordinate = NULL, $yCoordinate = NULL) { public static function ATAN2($xCoordinate = null, $yCoordinate = null)
{
$xCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($xCoordinate); $xCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($xCoordinate);
$yCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($yCoordinate); $yCoordinate = PHPExcel_Calculation_Functions::flattenSingleValue($yCoordinate);
$xCoordinate = ($xCoordinate !== NULL) ? $xCoordinate : 0.0; $xCoordinate = ($xCoordinate !== null) ? $xCoordinate : 0.0;
$yCoordinate = ($yCoordinate !== NULL) ? $yCoordinate : 0.0; $yCoordinate = ($yCoordinate !== null) ? $yCoordinate : 0.0;
if (((is_numeric($xCoordinate)) || (is_bool($xCoordinate))) && if (((is_numeric($xCoordinate)) || (is_bool($xCoordinate))) &&
((is_numeric($yCoordinate))) || (is_bool($yCoordinate))) { ((is_numeric($yCoordinate))) || (is_bool($yCoordinate))) {
@ -116,7 +110,7 @@ class PHPExcel_Calculation_MathTrig {
return atan2($yCoordinate, $xCoordinate); return atan2($yCoordinate, $xCoordinate);
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function ATAN2() }
/** /**
@ -136,7 +130,8 @@ class PHPExcel_Calculation_MathTrig {
* @param float $significance The multiple to which you want to round. * @param float $significance The multiple to which you want to round.
* @return float Rounded Number * @return float Rounded Number
*/ */
public static function CEILING($number, $significance = NULL) { public static function CEILING($number, $significance = null)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance); $significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance);
@ -155,7 +150,7 @@ class PHPExcel_Calculation_MathTrig {
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function CEILING() }
/** /**
@ -173,7 +168,8 @@ class PHPExcel_Calculation_MathTrig {
* @param int $numInSet Number of objects in each combination * @param int $numInSet Number of objects in each combination
* @return int Number of combinations * @return int Number of combinations
*/ */
public static function COMBIN($numObjs, $numInSet) { public static function COMBIN($numObjs, $numInSet)
{
$numObjs = PHPExcel_Calculation_Functions::flattenSingleValue($numObjs); $numObjs = PHPExcel_Calculation_Functions::flattenSingleValue($numObjs);
$numInSet = PHPExcel_Calculation_Functions::flattenSingleValue($numInSet); $numInSet = PHPExcel_Calculation_Functions::flattenSingleValue($numInSet);
@ -186,7 +182,7 @@ class PHPExcel_Calculation_MathTrig {
return round(self::FACT($numObjs) / self::FACT($numObjs - $numInSet)) / self::FACT($numInSet); return round(self::FACT($numObjs) / self::FACT($numObjs - $numInSet)) / self::FACT($numInSet);
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function COMBIN() }
/** /**
@ -206,7 +202,8 @@ class PHPExcel_Calculation_MathTrig {
* @param float $number Number to round * @param float $number Number to round
* @return int Rounded Number * @return int Rounded Number
*/ */
public static function EVEN($number) { public static function EVEN($number)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
if (is_null($number)) { if (is_null($number)) {
@ -220,7 +217,7 @@ class PHPExcel_Calculation_MathTrig {
return (int) self::CEILING($number, $significance); return (int) self::CEILING($number, $significance);
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function EVEN() }
/** /**
@ -237,7 +234,8 @@ class PHPExcel_Calculation_MathTrig {
* @param float $factVal Factorial Value * @param float $factVal Factorial Value
* @return int Factorial * @return int Factorial
*/ */
public static function FACT($factVal) { public static function FACT($factVal)
{
$factVal = PHPExcel_Calculation_Functions::flattenSingleValue($factVal); $factVal = PHPExcel_Calculation_Functions::flattenSingleValue($factVal);
if (is_numeric($factVal)) { if (is_numeric($factVal)) {
@ -258,7 +256,7 @@ class PHPExcel_Calculation_MathTrig {
return $factorial ; return $factorial ;
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function FACT() }
/** /**
@ -274,7 +272,8 @@ class PHPExcel_Calculation_MathTrig {
* @param float $factVal Factorial Value * @param float $factVal Factorial Value
* @return int Double Factorial * @return int Double Factorial
*/ */
public static function FACTDOUBLE($factVal) { public static function FACTDOUBLE($factVal)
{
$factLoop = PHPExcel_Calculation_Functions::flattenSingleValue($factVal); $factLoop = PHPExcel_Calculation_Functions::flattenSingleValue($factVal);
if (is_numeric($factLoop)) { if (is_numeric($factLoop)) {
@ -290,7 +289,7 @@ class PHPExcel_Calculation_MathTrig {
return $factorial ; return $factorial ;
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function FACTDOUBLE() }
/** /**
@ -307,11 +306,13 @@ class PHPExcel_Calculation_MathTrig {
* @param float $significance Significance * @param float $significance Significance
* @return float Rounded Number * @return float Rounded Number
*/ */
public static function FLOOR($number, $significance = NULL) { public static function FLOOR($number, $significance = null)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance); $significance = PHPExcel_Calculation_Functions::flattenSingleValue($significance);
if ((is_null($significance)) && (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) { if ((is_null($significance)) &&
(PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) {
$significance = $number/abs($number); $significance = $number/abs($number);
} }
@ -325,10 +326,10 @@ class PHPExcel_Calculation_MathTrig {
} else { } else {
return PHPExcel_Calculation_Functions::NaN(); return PHPExcel_Calculation_Functions::NaN();
} }
} else }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function FLOOR() }
/** /**
@ -346,7 +347,8 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed $arg,... Data values * @param mixed $arg,... Data values
* @return integer Greatest Common Divisor * @return integer Greatest Common Divisor
*/ */
public static function GCD() { public static function GCD()
{
$returnValue = 1; $returnValue = 1;
$allValuesFactors = array(); $allValuesFactors = array();
// Loop through arguments // Loop through arguments
@ -358,7 +360,7 @@ class PHPExcel_Calculation_MathTrig {
} elseif ($value < 0) { } elseif ($value < 0) {
return PHPExcel_Calculation_Functions::NaN(); return PHPExcel_Calculation_Functions::NaN();
} }
$myFactors = self::_factors($value); $myFactors = self::factors($value);
$myCountedFactors = array_count_values($myFactors); $myCountedFactors = array_count_values($myFactors);
$allValuesFactors[] = $myCountedFactors; $allValuesFactors[] = $myCountedFactors;
} }
@ -404,7 +406,7 @@ class PHPExcel_Calculation_MathTrig {
} }
return pow($key, $value); return pow($key, $value);
} }
} // function GCD() }
/** /**
@ -420,7 +422,8 @@ class PHPExcel_Calculation_MathTrig {
* @param float $number Number to cast to an integer * @param float $number Number to cast to an integer
* @return integer Integer value * @return integer Integer value
*/ */
public static function INT($number) { public static function INT($number)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
if (is_null($number)) { if (is_null($number)) {
@ -432,7 +435,7 @@ class PHPExcel_Calculation_MathTrig {
return (int) floor($number); return (int) floor($number);
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function INT() }
/** /**
@ -451,7 +454,8 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed $arg,... Data values * @param mixed $arg,... Data values
* @return int Lowest Common Multiplier * @return int Lowest Common Multiplier
*/ */
public static function LCM() { public static function LCM()
{
$returnValue = 1; $returnValue = 1;
$allPoweredFactors = array(); $allPoweredFactors = array();
// Loop through arguments // Loop through arguments
@ -464,7 +468,7 @@ class PHPExcel_Calculation_MathTrig {
} elseif ($value < 0) { } elseif ($value < 0) {
return PHPExcel_Calculation_Functions::NaN(); return PHPExcel_Calculation_Functions::NaN();
} }
$myFactors = self::_factors(floor($value)); $myFactors = self::factors(floor($value));
$myCountedFactors = array_count_values($myFactors); $myCountedFactors = array_count_values($myFactors);
$myPoweredFactors = array(); $myPoweredFactors = array();
foreach ($myCountedFactors as $myCountedFactor => $myCountedPower) { foreach ($myCountedFactors as $myCountedFactor => $myCountedPower) {
@ -484,7 +488,7 @@ class PHPExcel_Calculation_MathTrig {
$returnValue *= (integer) $allPoweredFactor; $returnValue *= (integer) $allPoweredFactor;
} }
return $returnValue; return $returnValue;
} // function LCM() }
/** /**
@ -501,16 +505,19 @@ class PHPExcel_Calculation_MathTrig {
* @param float $base The base of the logarithm. If base is omitted, it is assumed to be 10. * @param float $base The base of the logarithm. If base is omitted, it is assumed to be 10.
* @return float * @return float
*/ */
public static function LOG_BASE($number = NULL, $base = 10) { public static function LOG_BASE($number = null, $base = 10)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$base = (is_null($base)) ? 10 : (float) PHPExcel_Calculation_Functions::flattenSingleValue($base); $base = (is_null($base)) ? 10 : (float) PHPExcel_Calculation_Functions::flattenSingleValue($base);
if ((!is_numeric($base)) || (!is_numeric($number))) if ((!is_numeric($base)) || (!is_numeric($number))) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
if (($base <= 0) || ($number <= 0)) }
if (($base <= 0) || ($number <= 0)) {
return PHPExcel_Calculation_Functions::NaN(); return PHPExcel_Calculation_Functions::NaN();
}
return log($number, $base); return log($number, $base);
} // function LOG_BASE() }
/** /**
@ -526,13 +533,18 @@ class PHPExcel_Calculation_MathTrig {
* @param array $matrixValues A matrix of values * @param array $matrixValues A matrix of values
* @return float * @return float
*/ */
public static function MDETERM($matrixValues) { public static function MDETERM($matrixValues)
{
$matrixData = array(); $matrixData = array();
if (!is_array($matrixValues)) { $matrixValues = array(array($matrixValues)); } if (!is_array($matrixValues)) {
$matrixValues = array(array($matrixValues));
}
$row = $maxColumn = 0; $row = $maxColumn = 0;
foreach ($matrixValues as $matrixRow) { foreach ($matrixValues as $matrixRow) {
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } if (!is_array($matrixRow)) {
$matrixRow = array($matrixRow);
}
$column = 0; $column = 0;
foreach ($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
if ((is_string($matrixCell)) || ($matrixCell === null)) { if ((is_string($matrixCell)) || ($matrixCell === null)) {
@ -541,10 +553,14 @@ class PHPExcel_Calculation_MathTrig {
$matrixData[$column][$row] = $matrixCell; $matrixData[$column][$row] = $matrixCell;
++$column; ++$column;
} }
if ($column > $maxColumn) { $maxColumn = $column; } if ($column > $maxColumn) {
$maxColumn = $column;
}
++$row; ++$row;
} }
if ($row != $maxColumn) { return PHPExcel_Calculation_Functions::VALUE(); } if ($row != $maxColumn) {
return PHPExcel_Calculation_Functions::VALUE();
}
try { try {
$matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData); $matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData);
@ -552,7 +568,7 @@ class PHPExcel_Calculation_MathTrig {
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
} // function MDETERM() }
/** /**
@ -568,13 +584,18 @@ class PHPExcel_Calculation_MathTrig {
* @param array $matrixValues A matrix of values * @param array $matrixValues A matrix of values
* @return array * @return array
*/ */
public static function MINVERSE($matrixValues) { public static function MINVERSE($matrixValues)
{
$matrixData = array(); $matrixData = array();
if (!is_array($matrixValues)) { $matrixValues = array(array($matrixValues)); } if (!is_array($matrixValues)) {
$matrixValues = array(array($matrixValues));
}
$row = $maxColumn = 0; $row = $maxColumn = 0;
foreach ($matrixValues as $matrixRow) { foreach ($matrixValues as $matrixRow) {
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } if (!is_array($matrixRow)) {
$matrixRow = array($matrixRow);
}
$column = 0; $column = 0;
foreach ($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
if ((is_string($matrixCell)) || ($matrixCell === null)) { if ((is_string($matrixCell)) || ($matrixCell === null)) {
@ -583,10 +604,14 @@ class PHPExcel_Calculation_MathTrig {
$matrixData[$column][$row] = $matrixCell; $matrixData[$column][$row] = $matrixCell;
++$column; ++$column;
} }
if ($column > $maxColumn) { $maxColumn = $column; } if ($column > $maxColumn) {
$maxColumn = $column;
}
++$row; ++$row;
} }
if ($row != $maxColumn) { return PHPExcel_Calculation_Functions::VALUE(); } if ($row != $maxColumn) {
return PHPExcel_Calculation_Functions::VALUE();
}
try { try {
$matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData); $matrix = new PHPExcel_Shared_JAMA_Matrix($matrixData);
@ -594,7 +619,7 @@ class PHPExcel_Calculation_MathTrig {
} catch (PHPExcel_Exception $ex) { } catch (PHPExcel_Exception $ex) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
} // function MINVERSE() }
/** /**
@ -604,15 +629,22 @@ class PHPExcel_Calculation_MathTrig {
* @param array $matrixData2 A matrix of values * @param array $matrixData2 A matrix of values
* @return array * @return array
*/ */
public static function MMULT($matrixData1,$matrixData2) { public static function MMULT($matrixData1, $matrixData2)
{
$matrixAData = $matrixBData = array(); $matrixAData = $matrixBData = array();
if (!is_array($matrixData1)) { $matrixData1 = array(array($matrixData1)); } if (!is_array($matrixData1)) {
if (!is_array($matrixData2)) { $matrixData2 = array(array($matrixData2)); } $matrixData1 = array(array($matrixData1));
}
if (!is_array($matrixData2)) {
$matrixData2 = array(array($matrixData2));
}
try { try {
$rowA = 0; $rowA = 0;
foreach ($matrixData1 as $matrixRow) { foreach ($matrixData1 as $matrixRow) {
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } if (!is_array($matrixRow)) {
$matrixRow = array($matrixRow);
}
$columnA = 0; $columnA = 0;
foreach ($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
if ((!is_numeric($matrixCell)) || ($matrixCell === null)) { if ((!is_numeric($matrixCell)) || ($matrixCell === null)) {
@ -626,7 +658,9 @@ class PHPExcel_Calculation_MathTrig {
$matrixA = new PHPExcel_Shared_JAMA_Matrix($matrixAData); $matrixA = new PHPExcel_Shared_JAMA_Matrix($matrixAData);
$rowB = 0; $rowB = 0;
foreach ($matrixData2 as $matrixRow) { foreach ($matrixData2 as $matrixRow) {
if (!is_array($matrixRow)) { $matrixRow = array($matrixRow); } if (!is_array($matrixRow)) {
$matrixRow = array($matrixRow);
}
$columnB = 0; $columnB = 0;
foreach ($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
if ((!is_numeric($matrixCell)) || ($matrixCell === null)) { if ((!is_numeric($matrixCell)) || ($matrixCell === null)) {
@ -648,7 +682,7 @@ class PHPExcel_Calculation_MathTrig {
var_dump($ex->getMessage()); var_dump($ex->getMessage());
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
} // function MMULT() }
/** /**
@ -658,7 +692,8 @@ class PHPExcel_Calculation_MathTrig {
* @param int $b Divisor * @param int $b Divisor
* @return int Remainder * @return int Remainder
*/ */
public static function MOD($a = 1, $b = 1) { public static function MOD($a = 1, $b = 1)
{
$a = PHPExcel_Calculation_Functions::flattenSingleValue($a); $a = PHPExcel_Calculation_Functions::flattenSingleValue($a);
$b = PHPExcel_Calculation_Functions::flattenSingleValue($b); $b = PHPExcel_Calculation_Functions::flattenSingleValue($b);
@ -671,7 +706,7 @@ class PHPExcel_Calculation_MathTrig {
} }
return fmod($a, $b); return fmod($a, $b);
} // function MOD() }
/** /**
@ -683,7 +718,8 @@ class PHPExcel_Calculation_MathTrig {
* @param int $multiple Multiple to which you want to round $number * @param int $multiple Multiple to which you want to round $number
* @return float Rounded Number * @return float Rounded Number
*/ */
public static function MROUND($number,$multiple) { public static function MROUND($number, $multiple)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$multiple = PHPExcel_Calculation_Functions::flattenSingleValue($multiple); $multiple = PHPExcel_Calculation_Functions::flattenSingleValue($multiple);
@ -698,7 +734,7 @@ class PHPExcel_Calculation_MathTrig {
return PHPExcel_Calculation_Functions::NaN(); return PHPExcel_Calculation_Functions::NaN();
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function MROUND() }
/** /**
@ -709,7 +745,8 @@ class PHPExcel_Calculation_MathTrig {
* @param array of mixed Data Series * @param array of mixed Data Series
* @return float * @return float
*/ */
public static function MULTINOMIAL() { public static function MULTINOMIAL()
{
$summer = 0; $summer = 0;
$divisor = 1; $divisor = 1;
// Loop through arguments // Loop through arguments
@ -732,7 +769,7 @@ class PHPExcel_Calculation_MathTrig {
return $summer / $divisor; return $summer / $divisor;
} }
return 0; return 0;
} // function MULTINOMIAL() }
/** /**
@ -743,16 +780,15 @@ class PHPExcel_Calculation_MathTrig {
* @param float $number Number to round * @param float $number Number to round
* @return int Rounded Number * @return int Rounded Number
*/ */
public static function ODD($number) { public static function ODD($number)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
if (is_null($number)) { if (is_null($number)) {
return 1; return 1;
} elseif (is_bool($number)) { } elseif (is_bool($number)) {
$number = (int) $number; return 1;
} } elseif (is_numeric($number)) {
if (is_numeric($number)) {
$significance = self::SIGN($number); $significance = self::SIGN($number);
if ($significance == 0) { if ($significance == 0) {
return 1; return 1;
@ -766,7 +802,7 @@ class PHPExcel_Calculation_MathTrig {
return (int) $result; return (int) $result;
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function ODD() }
/** /**
@ -778,7 +814,8 @@ class PHPExcel_Calculation_MathTrig {
* @param float $y * @param float $y
* @return float * @return float
*/ */
public static function POWER($x = 0, $y = 2) { public static function POWER($x = 0, $y = 2)
{
$x = PHPExcel_Calculation_Functions::flattenSingleValue($x); $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
$y = PHPExcel_Calculation_Functions::flattenSingleValue($y); $y = PHPExcel_Calculation_Functions::flattenSingleValue($y);
@ -792,7 +829,7 @@ class PHPExcel_Calculation_MathTrig {
// Return // Return
$result = pow($x, $y); $result = pow($x, $y);
return (!is_nan($result) && !is_infinite($result)) ? $result : PHPExcel_Calculation_Functions::NaN(); return (!is_nan($result) && !is_infinite($result)) ? $result : PHPExcel_Calculation_Functions::NaN();
} // function POWER() }
/** /**
@ -808,7 +845,8 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed $arg,... Data values * @param mixed $arg,... Data values
* @return float * @return float
*/ */
public static function PRODUCT() { public static function PRODUCT()
{
// Return value // Return value
$returnValue = null; $returnValue = null;
@ -829,7 +867,7 @@ class PHPExcel_Calculation_MathTrig {
return 0; return 0;
} }
return $returnValue; return $returnValue;
} // function PRODUCT() }
/** /**
@ -846,7 +884,8 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed $arg,... Data values * @param mixed $arg,... Data values
* @return float * @return float
*/ */
public static function QUOTIENT() { public static function QUOTIENT()
{
// Return value // Return value
$returnValue = null; $returnValue = null;
@ -868,7 +907,7 @@ class PHPExcel_Calculation_MathTrig {
// Return // Return
return intval($returnValue); return intval($returnValue);
} // function QUOTIENT() }
/** /**
@ -878,7 +917,8 @@ class PHPExcel_Calculation_MathTrig {
* @param int $max Maximal value * @param int $max Maximal value
* @return int Random number * @return int Random number
*/ */
public static function RAND($min = 0, $max = 0) { public static function RAND($min = 0, $max = 0)
{
$min = PHPExcel_Calculation_Functions::flattenSingleValue($min); $min = PHPExcel_Calculation_Functions::flattenSingleValue($min);
$max = PHPExcel_Calculation_Functions::flattenSingleValue($max); $max = PHPExcel_Calculation_Functions::flattenSingleValue($max);
@ -887,10 +927,11 @@ class PHPExcel_Calculation_MathTrig {
} else { } else {
return mt_rand($min, $max); return mt_rand($min, $max);
} }
} // function RAND() }
public static function ROMAN($aValue, $style=0) { public static function ROMAN($aValue, $style = 0)
{
$aValue = PHPExcel_Calculation_Functions::flattenSingleValue($aValue); $aValue = PHPExcel_Calculation_Functions::flattenSingleValue($aValue);
$style = (is_null($style)) ? 0 : (integer) PHPExcel_Calculation_Functions::flattenSingleValue($style); $style = (is_null($style)) ? 0 : (integer) PHPExcel_Calculation_Functions::flattenSingleValue($style);
if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) { if ((!is_numeric($aValue)) || ($aValue < 0) || ($aValue >= 4000)) {
@ -901,22 +942,25 @@ class PHPExcel_Calculation_MathTrig {
return ''; return '';
} }
$mill = Array('', 'M', 'MM', 'MMM', 'MMMM', 'MMMMM'); $mill = array('', 'M', 'MM', 'MMM', 'MMMM', 'MMMMM');
$cent = Array('', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'); $cent = array('', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM');
$tens = Array('', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'); $tens = array('', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC');
$ones = Array('', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'); $ones = array('', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX');
$roman = ''; $roman = '';
while ($aValue > 5999) { while ($aValue > 5999) {
$roman .= 'M'; $roman .= 'M';
$aValue -= 1000; $aValue -= 1000;
} }
$m = self::_romanCut($aValue, 1000); $aValue %= 1000; $m = self::romanCut($aValue, 1000);
$c = self::_romanCut($aValue, 100); $aValue %= 100; $aValue %= 1000;
$t = self::_romanCut($aValue, 10); $aValue %= 10; $c = self::romanCut($aValue, 100);
$aValue %= 100;
$t = self::romanCut($aValue, 10);
$aValue %= 10;
return $roman.$mill[$m].$cent[$c].$tens[$t].$ones[$aValue]; return $roman.$mill[$m].$cent[$c].$tens[$t].$ones[$aValue];
} // function ROMAN() }
/** /**
@ -928,7 +972,8 @@ class PHPExcel_Calculation_MathTrig {
* @param int $digits Number of digits to which you want to round $number * @param int $digits Number of digits to which you want to round $number
* @return float Rounded Number * @return float Rounded Number
*/ */
public static function ROUNDUP($number,$digits) { public static function ROUNDUP($number, $digits)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);
@ -941,7 +986,7 @@ class PHPExcel_Calculation_MathTrig {
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function ROUNDUP() }
/** /**
@ -953,7 +998,8 @@ class PHPExcel_Calculation_MathTrig {
* @param int $digits Number of digits to which you want to round $number * @param int $digits Number of digits to which you want to round $number
* @return float Rounded Number * @return float Rounded Number
*/ */
public static function ROUNDDOWN($number,$digits) { public static function ROUNDDOWN($number, $digits)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);
@ -966,7 +1012,7 @@ class PHPExcel_Calculation_MathTrig {
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function ROUNDDOWN() }
/** /**
@ -980,8 +1026,8 @@ class PHPExcel_Calculation_MathTrig {
* @param array of mixed Data Series * @param array of mixed Data Series
* @return float * @return float
*/ */
public static function SERIESSUM() { public static function SERIESSUM()
// Return value {
$returnValue = 0; $returnValue = 0;
// Loop through arguments // Loop through arguments
@ -1002,11 +1048,10 @@ class PHPExcel_Calculation_MathTrig {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} }
} }
// Return
return $returnValue; return $returnValue;
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function SERIESSUM() }
/** /**
@ -1018,11 +1063,13 @@ class PHPExcel_Calculation_MathTrig {
* @param float $number Number to round * @param float $number Number to round
* @return int sign value * @return int sign value
*/ */
public static function SIGN($number) { public static function SIGN($number)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
if (is_bool($number)) if (is_bool($number)) {
return (int) $number; return (int) $number;
}
if (is_numeric($number)) { if (is_numeric($number)) {
if ($number == 0.0) { if ($number == 0.0) {
return 0; return 0;
@ -1030,7 +1077,7 @@ class PHPExcel_Calculation_MathTrig {
return $number / abs($number); return $number / abs($number);
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function SIGN() }
/** /**
@ -1041,7 +1088,8 @@ class PHPExcel_Calculation_MathTrig {
* @param float $number Number * @param float $number Number
* @return float Square Root of Number * Pi * @return float Square Root of Number * Pi
*/ */
public static function SQRTPI($number) { public static function SQRTPI($number)
{
$number = PHPExcel_Calculation_Functions::flattenSingleValue($number); $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
if (is_numeric($number)) { if (is_numeric($number)) {
@ -1051,7 +1099,7 @@ class PHPExcel_Calculation_MathTrig {
return sqrt($number * M_PI) ; return sqrt($number * M_PI) ;
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function SQRTPI() }
/** /**
@ -1064,7 +1112,8 @@ class PHPExcel_Calculation_MathTrig {
* @param array of mixed Data Series * @param array of mixed Data Series
* @return float * @return float
*/ */
public static function SUBTOTAL() { public static function SUBTOTAL()
{
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
// Calculate // Calculate
@ -1074,41 +1123,30 @@ class PHPExcel_Calculation_MathTrig {
switch($subtotal) { switch($subtotal) {
case 1: case 1:
return PHPExcel_Calculation_Statistical::AVERAGE($aArgs); return PHPExcel_Calculation_Statistical::AVERAGE($aArgs);
break;
case 2: case 2:
return PHPExcel_Calculation_Statistical::COUNT($aArgs); return PHPExcel_Calculation_Statistical::COUNT($aArgs);
break;
case 3: case 3:
return PHPExcel_Calculation_Statistical::COUNTA($aArgs); return PHPExcel_Calculation_Statistical::COUNTA($aArgs);
break;
case 4: case 4:
return PHPExcel_Calculation_Statistical::MAX($aArgs); return PHPExcel_Calculation_Statistical::MAX($aArgs);
break;
case 5: case 5:
return PHPExcel_Calculation_Statistical::MIN($aArgs); return PHPExcel_Calculation_Statistical::MIN($aArgs);
break;
case 6: case 6:
return self::PRODUCT($aArgs); return self::PRODUCT($aArgs);
break;
case 7: case 7:
return PHPExcel_Calculation_Statistical::STDEV($aArgs); return PHPExcel_Calculation_Statistical::STDEV($aArgs);
break;
case 8: case 8:
return PHPExcel_Calculation_Statistical::STDEVP($aArgs); return PHPExcel_Calculation_Statistical::STDEVP($aArgs);
break;
case 9: case 9:
return self::SUM($aArgs); return self::SUM($aArgs);
break;
case 10: case 10:
return PHPExcel_Calculation_Statistical::VARFunc($aArgs); return PHPExcel_Calculation_Statistical::VARFunc($aArgs);
break;
case 11: case 11:
return PHPExcel_Calculation_Statistical::VARP($aArgs); return PHPExcel_Calculation_Statistical::VARP($aArgs);
break;
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function SUBTOTAL() }
/** /**
@ -1124,8 +1162,8 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed $arg,... Data values * @param mixed $arg,... Data values
* @return float * @return float
*/ */
public static function SUM() { public static function SUM()
// Return value {
$returnValue = 0; $returnValue = 0;
// Loop through the arguments // Loop through the arguments
@ -1136,9 +1174,8 @@ class PHPExcel_Calculation_MathTrig {
} }
} }
// Return
return $returnValue; return $returnValue;
} // function SUM() }
/** /**
@ -1155,8 +1192,8 @@ class PHPExcel_Calculation_MathTrig {
* @param string $condition The criteria that defines which cells will be summed. * @param string $condition The criteria that defines which cells will be summed.
* @return float * @return float
*/ */
public static function SUMIF($aArgs,$condition,$sumArgs = array()) { public static function SUMIF($aArgs, $condition, $sumArgs = array())
// Return value {
$returnValue = 0; $returnValue = 0;
$aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs); $aArgs = PHPExcel_Calculation_Functions::flattenArray($aArgs);
@ -1179,9 +1216,8 @@ class PHPExcel_Calculation_MathTrig {
} }
} }
// Return
return $returnValue; return $returnValue;
} // function SUMIF() }
/** /**
@ -1195,7 +1231,8 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed $arg,... Data values * @param mixed $arg,... Data values
* @return float * @return float
*/ */
public static function SUMPRODUCT() { public static function SUMPRODUCT()
{
$arrayList = func_get_args(); $arrayList = func_get_args();
$wrkArray = PHPExcel_Calculation_Functions::flattenArray(array_shift($arrayList)); $wrkArray = PHPExcel_Calculation_Functions::flattenArray(array_shift($arrayList));
@ -1223,7 +1260,7 @@ class PHPExcel_Calculation_MathTrig {
} }
return array_sum($wrkArray); return array_sum($wrkArray);
} // function SUMPRODUCT() }
/** /**
@ -1239,8 +1276,8 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed $arg,... Data values * @param mixed $arg,... Data values
* @return float * @return float
*/ */
public static function SUMSQ() { public static function SUMSQ()
// Return value {
$returnValue = 0; $returnValue = 0;
// Loop through arguments // Loop through arguments
@ -1251,9 +1288,8 @@ class PHPExcel_Calculation_MathTrig {
} }
} }
// Return
return $returnValue; return $returnValue;
} // function SUMSQ() }
/** /**
@ -1263,16 +1299,11 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed[] $matrixData2 Matrix #2 * @param mixed[] $matrixData2 Matrix #2
* @return float * @return float
*/ */
public static function SUMX2MY2($matrixData1,$matrixData2) { public static function SUMX2MY2($matrixData1, $matrixData2)
{
$array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1);
$array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2);
$count1 = count($array1); $count = min(count($array1), count($array2));
$count2 = count($array2);
if ($count1 < $count2) {
$count = $count1;
} else {
$count = $count2;
}
$result = 0; $result = 0;
for ($i = 0; $i < $count; ++$i) { for ($i = 0; $i < $count; ++$i) {
@ -1283,7 +1314,7 @@ class PHPExcel_Calculation_MathTrig {
} }
return $result; return $result;
} // function SUMX2MY2() }
/** /**
@ -1293,16 +1324,11 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed[] $matrixData2 Matrix #2 * @param mixed[] $matrixData2 Matrix #2
* @return float * @return float
*/ */
public static function SUMX2PY2($matrixData1,$matrixData2) { public static function SUMX2PY2($matrixData1, $matrixData2)
{
$array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1);
$array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2);
$count1 = count($array1); $count = min(count($array1), count($array2));
$count2 = count($array2);
if ($count1 < $count2) {
$count = $count1;
} else {
$count = $count2;
}
$result = 0; $result = 0;
for ($i = 0; $i < $count; ++$i) { for ($i = 0; $i < $count; ++$i) {
@ -1313,7 +1339,7 @@ class PHPExcel_Calculation_MathTrig {
} }
return $result; return $result;
} // function SUMX2PY2() }
/** /**
@ -1323,16 +1349,11 @@ class PHPExcel_Calculation_MathTrig {
* @param mixed[] $matrixData2 Matrix #2 * @param mixed[] $matrixData2 Matrix #2
* @return float * @return float
*/ */
public static function SUMXMY2($matrixData1,$matrixData2) { public static function SUMXMY2($matrixData1, $matrixData2)
{
$array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1); $array1 = PHPExcel_Calculation_Functions::flattenArray($matrixData1);
$array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2); $array2 = PHPExcel_Calculation_Functions::flattenArray($matrixData2);
$count1 = count($array1); $count = min(count($array1), count($array2));
$count2 = count($array2);
if ($count1 < $count2) {
$count = $count1;
} else {
$count = $count2;
}
$result = 0; $result = 0;
for ($i = 0; $i < $count; ++$i) { for ($i = 0; $i < $count; ++$i) {
@ -1343,7 +1364,7 @@ class PHPExcel_Calculation_MathTrig {
} }
return $result; return $result;
} // function SUMXMY2() }
/** /**
@ -1355,22 +1376,24 @@ class PHPExcel_Calculation_MathTrig {
* @param int $digits * @param int $digits
* @return float Truncated value * @return float Truncated value
*/ */
public static function TRUNC($value = 0, $digits = 0) { public static function TRUNC($value = 0, $digits = 0)
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits); $digits = PHPExcel_Calculation_Functions::flattenSingleValue($digits);
// Validate parameters // Validate parameters
if ((!is_numeric($value)) || (!is_numeric($digits))) if ((!is_numeric($value)) || (!is_numeric($digits))) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
}
$digits = floor($digits); $digits = floor($digits);
// Truncate // Truncate
$adjust = pow(10, $digits); $adjust = pow(10, $digits);
if (($digits > 0) && (rtrim(intval((abs($value) - abs(intval($value))) * $adjust),'0') < $adjust/10)) if (($digits > 0) && (rtrim(intval((abs($value) - abs(intval($value))) * $adjust), '0') < $adjust/10)) {
return $value; return $value;
}
return (intval($value * $adjust)) / $adjust; return (intval($value * $adjust)) / $adjust;
} // function TRUNC() }
}
} // class PHPExcel_Calculation_MathTrig

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,16 @@
<?php <?php
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/** /**
* PHPExcel * @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_TextData
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,46 +34,30 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
class PHPExcel_Calculation_TextData
{
private static $invalidChars;
private static function unicodeToOrd($c)
/** PHPExcel root directory */ {
if (!defined('PHPEXCEL_ROOT')) { if (ord($c{0}) >=0 && ord($c{0}) <= 127) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_TextData
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_TextData {
private static $_invalidChars = Null;
private static function _uniord($c) {
if (ord($c{0}) >=0 && ord($c{0}) <= 127)
return ord($c{0}); return ord($c{0});
if (ord($c{0}) >= 192 && ord($c{0}) <= 223) } elseif (ord($c{0}) >= 192 && ord($c{0}) <= 223) {
return (ord($c{0})-192)*64 + (ord($c{1})-128); return (ord($c{0})-192)*64 + (ord($c{1})-128);
if (ord($c{0}) >= 224 && ord($c{0}) <= 239) } elseif (ord($c{0}) >= 224 && ord($c{0}) <= 239) {
return (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128); return (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
if (ord($c{0}) >= 240 && ord($c{0}) <= 247) } elseif (ord($c{0}) >= 240 && ord($c{0}) <= 247) {
return (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128); return (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
if (ord($c{0}) >= 248 && ord($c{0}) <= 251) } elseif (ord($c{0}) >= 248 && ord($c{0}) <= 251) {
return (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128); return (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
if (ord($c{0}) >= 252 && ord($c{0}) <= 253) } elseif (ord($c{0}) >= 252 && ord($c{0}) <= 253) {
return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
if (ord($c{0}) >= 254 && ord($c{0}) <= 255) //error } elseif (ord($c{0}) >= 254 && ord($c{0}) <= 255) {
// error
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
}
return 0; return 0;
} // function _uniord() }
/** /**
* CHARACTER * CHARACTER
@ -71,7 +65,8 @@ class PHPExcel_Calculation_TextData {
* @param string $character Value * @param string $character Value
* @return int * @return int
*/ */
public static function CHARACTER($character) { public static function CHARACTER($character)
{
$character = PHPExcel_Calculation_Functions::flattenSingleValue($character); $character = PHPExcel_Calculation_Functions::flattenSingleValue($character);
if ((!is_numeric($character)) || ($character < 0)) { if ((!is_numeric($character)) || ($character < 0)) {
@ -92,22 +87,23 @@ class PHPExcel_Calculation_TextData {
* @param mixed $stringValue Value to check * @param mixed $stringValue Value to check
* @return string * @return string
*/ */
public static function TRIMNONPRINTABLE($stringValue = '') { public static function TRIMNONPRINTABLE($stringValue = '')
{
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
if (is_bool($stringValue)) { if (is_bool($stringValue)) {
return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
} }
if (self::$_invalidChars == Null) { if (self::$invalidChars == null) {
self::$_invalidChars = range(chr(0),chr(31)); self::$invalidChars = range(chr(0), chr(31));
} }
if (is_string($stringValue) || is_numeric($stringValue)) { if (is_string($stringValue) || is_numeric($stringValue)) {
return str_replace(self::$_invalidChars, '', trim($stringValue, "\x00..\x1F")); return str_replace(self::$invalidChars, '', trim($stringValue, "\x00..\x1F"));
}
return null;
} }
return NULL;
} // function TRIMNONPRINTABLE()
/** /**
@ -116,7 +112,8 @@ class PHPExcel_Calculation_TextData {
* @param mixed $stringValue Value to check * @param mixed $stringValue Value to check
* @return string * @return string
*/ */
public static function TRIMSPACES($stringValue = '') { public static function TRIMSPACES($stringValue = '')
{
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue); $stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
if (is_bool($stringValue)) { if (is_bool($stringValue)) {
return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE(); return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
@ -125,8 +122,8 @@ class PHPExcel_Calculation_TextData {
if (is_string($stringValue) || is_numeric($stringValue)) { if (is_string($stringValue) || is_numeric($stringValue)) {
return trim(preg_replace('/ +/', ' ', trim($stringValue, ' ')), ' '); return trim(preg_replace('/ +/', ' ', trim($stringValue, ' ')), ' ');
} }
return NULL; return null;
} // function TRIMSPACES() }
/** /**
@ -135,9 +132,11 @@ class PHPExcel_Calculation_TextData {
* @param string $characters Value * @param string $characters Value
* @return int * @return int
*/ */
public static function ASCIICODE($characters) { public static function ASCIICODE($characters)
if (($characters === NULL) || ($characters === '')) {
if (($characters === null) || ($characters === '')) {
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
}
$characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters); $characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters);
if (is_bool($characters)) { if (is_bool($characters)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
@ -149,13 +148,17 @@ class PHPExcel_Calculation_TextData {
$character = $characters; $character = $characters;
if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) { if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) {
if (mb_strlen($characters, 'UTF-8') > 1) { $character = mb_substr($characters, 0, 1, 'UTF-8'); } if (mb_strlen($characters, 'UTF-8') > 1) {
return self::_uniord($character); $character = mb_substr($characters, 0, 1, 'UTF-8');
}
return self::unicodeToOrd($character);
} else { } else {
if (strlen($characters) > 0) { $character = substr($characters, 0, 1); } if (strlen($characters) > 0) {
$character = substr($characters, 0, 1);
}
return ord($character); return ord($character);
} }
} // function ASCIICODE() }
/** /**
@ -163,8 +166,8 @@ class PHPExcel_Calculation_TextData {
* *
* @return string * @return string
*/ */
public static function CONCATENATE() { public static function CONCATENATE()
// Return value {
$returnValue = ''; $returnValue = '';
// Loop through arguments // Loop through arguments
@ -180,9 +183,8 @@ class PHPExcel_Calculation_TextData {
$returnValue .= $arg; $returnValue .= $arg;
} }
// Return
return $returnValue; return $returnValue;
} // function CONCATENATE() }
/** /**
@ -197,7 +199,8 @@ class PHPExcel_Calculation_TextData {
* If you omit decimals, it is assumed to be 2 * If you omit decimals, it is assumed to be 2
* @return string * @return string
*/ */
public static function DOLLAR($value = 0, $decimals = 2) { public static function DOLLAR($value = 0, $decimals = 2)
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals); $decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
@ -212,13 +215,15 @@ class PHPExcel_Calculation_TextData {
$mask .= '.' . str_repeat('0', $decimals); $mask .= '.' . str_repeat('0', $decimals);
} else { } else {
$round = pow(10, abs($decimals)); $round = pow(10, abs($decimals));
if ($value < 0) { $round = 0-$round; } if ($value < 0) {
$round = 0-$round;
}
$value = PHPExcel_Calculation_MathTrig::MROUND($value, $round); $value = PHPExcel_Calculation_MathTrig::MROUND($value, $round);
} }
return PHPExcel_Style_NumberFormat::toFormattedString($value, $mask); return PHPExcel_Style_NumberFormat::toFormattedString($value, $mask);
} // function DOLLAR() }
/** /**
@ -229,7 +234,8 @@ class PHPExcel_Calculation_TextData {
* @param int $offset Offset within $haystack * @param int $offset Offset within $haystack
* @return string * @return string
*/ */
public static function SEARCHSENSITIVE($needle,$haystack,$offset=1) { public static function SEARCHSENSITIVE($needle, $haystack, $offset = 1)
{
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); $needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle);
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); $haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack);
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); $offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset);
@ -254,7 +260,7 @@ class PHPExcel_Calculation_TextData {
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function SEARCHSENSITIVE() }
/** /**
@ -265,7 +271,8 @@ class PHPExcel_Calculation_TextData {
* @param int $offset Offset within $haystack * @param int $offset Offset within $haystack
* @return string * @return string
*/ */
public static function SEARCHINSENSITIVE($needle,$haystack,$offset=1) { public static function SEARCHINSENSITIVE($needle, $haystack, $offset = 1)
{
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle); $needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle);
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack); $haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack);
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset); $offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset);
@ -290,7 +297,7 @@ class PHPExcel_Calculation_TextData {
} }
} }
return PHPExcel_Calculation_Functions::VALUE(); return PHPExcel_Calculation_Functions::VALUE();
} // function SEARCHINSENSITIVE() }
/** /**
@ -301,7 +308,8 @@ class PHPExcel_Calculation_TextData {
* @param boolean $no_commas * @param boolean $no_commas
* @return boolean * @return boolean
*/ */
public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = FALSE) { public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = false)
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals); $decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
$no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas); $no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas);
@ -313,13 +321,15 @@ class PHPExcel_Calculation_TextData {
$decimals = floor($decimals); $decimals = floor($decimals);
$valueResult = round($value, $decimals); $valueResult = round($value, $decimals);
if ($decimals < 0) { $decimals = 0; } if ($decimals < 0) {
$decimals = 0;
}
if (!$no_commas) { if (!$no_commas) {
$valueResult = number_format($valueResult, $decimals); $valueResult = number_format($valueResult, $decimals);
} }
return (string) $valueResult; return (string) $valueResult;
} // function FIXEDFORMAT() }
/** /**
@ -329,7 +339,8 @@ class PHPExcel_Calculation_TextData {
* @param int $chars Number of characters * @param int $chars Number of characters
* @return string * @return string
*/ */
public static function LEFT($value = '', $chars = 1) { public static function LEFT($value = '', $chars = 1)
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
@ -346,7 +357,7 @@ class PHPExcel_Calculation_TextData {
} else { } else {
return substr($value, 0, $chars); return substr($value, 0, $chars);
} }
} // function LEFT() }
/** /**
@ -357,7 +368,8 @@ class PHPExcel_Calculation_TextData {
* @param int $chars Number of characters * @param int $chars Number of characters
* @return string * @return string
*/ */
public static function MID($value = '', $start = 1, $chars = null) { public static function MID($value = '', $start = 1, $chars = null)
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start); $start = PHPExcel_Calculation_Functions::flattenSingleValue($start);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
@ -375,7 +387,7 @@ class PHPExcel_Calculation_TextData {
} else { } else {
return substr($value, --$start, $chars); return substr($value, --$start, $chars);
} }
} // function MID() }
/** /**
@ -385,7 +397,8 @@ class PHPExcel_Calculation_TextData {
* @param int $chars Number of characters * @param int $chars Number of characters
* @return string * @return string
*/ */
public static function RIGHT($value = '', $chars = 1) { public static function RIGHT($value = '', $chars = 1)
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
@ -402,7 +415,7 @@ class PHPExcel_Calculation_TextData {
} else { } else {
return substr($value, strlen($value) - $chars); return substr($value, strlen($value) - $chars);
} }
} // function RIGHT() }
/** /**
@ -411,7 +424,8 @@ class PHPExcel_Calculation_TextData {
* @param string $value Value * @param string $value Value
* @return string * @return string
*/ */
public static function STRINGLENGTH($value = '') { public static function STRINGLENGTH($value = '')
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
if (is_bool($value)) { if (is_bool($value)) {
@ -423,7 +437,7 @@ class PHPExcel_Calculation_TextData {
} else { } else {
return strlen($value); return strlen($value);
} }
} // function STRINGLENGTH() }
/** /**
@ -434,7 +448,8 @@ class PHPExcel_Calculation_TextData {
* @param string $mixedCaseString * @param string $mixedCaseString
* @return string * @return string
*/ */
public static function LOWERCASE($mixedCaseString) { public static function LOWERCASE($mixedCaseString)
{
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) { if (is_bool($mixedCaseString)) {
@ -442,7 +457,7 @@ class PHPExcel_Calculation_TextData {
} }
return PHPExcel_Shared_String::StrToLower($mixedCaseString); return PHPExcel_Shared_String::StrToLower($mixedCaseString);
} // function LOWERCASE() }
/** /**
@ -453,7 +468,8 @@ class PHPExcel_Calculation_TextData {
* @param string $mixedCaseString * @param string $mixedCaseString
* @return string * @return string
*/ */
public static function UPPERCASE($mixedCaseString) { public static function UPPERCASE($mixedCaseString)
{
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) { if (is_bool($mixedCaseString)) {
@ -461,7 +477,7 @@ class PHPExcel_Calculation_TextData {
} }
return PHPExcel_Shared_String::StrToUpper($mixedCaseString); return PHPExcel_Shared_String::StrToUpper($mixedCaseString);
} // function UPPERCASE() }
/** /**
@ -472,7 +488,8 @@ class PHPExcel_Calculation_TextData {
* @param string $mixedCaseString * @param string $mixedCaseString
* @return string * @return string
*/ */
public static function PROPERCASE($mixedCaseString) { public static function PROPERCASE($mixedCaseString)
{
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString); $mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) { if (is_bool($mixedCaseString)) {
@ -480,7 +497,7 @@ class PHPExcel_Calculation_TextData {
} }
return PHPExcel_Shared_String::StrToTitle($mixedCaseString); return PHPExcel_Shared_String::StrToTitle($mixedCaseString);
} // function PROPERCASE() }
/** /**
@ -492,7 +509,8 @@ class PHPExcel_Calculation_TextData {
* @param string $newText String to replace in defined position * @param string $newText String to replace in defined position
* @return string * @return string
*/ */
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) { public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText)
{
$oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText); $oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText);
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start); $start = PHPExcel_Calculation_Functions::flattenSingleValue($start);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars); $chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
@ -502,7 +520,7 @@ class PHPExcel_Calculation_TextData {
$right = self::RIGHT($oldText, self::STRINGLENGTH($oldText)-($start+$chars)+1); $right = self::RIGHT($oldText, self::STRINGLENGTH($oldText)-($start+$chars)+1);
return $left.$newText.$right; return $left.$newText.$right;
} // function REPLACE() }
/** /**
@ -514,7 +532,8 @@ class PHPExcel_Calculation_TextData {
* @param integer $instance Instance Number * @param integer $instance Instance Number
* @return string * @return string
*/ */
public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) { public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0)
{
$text = PHPExcel_Calculation_Functions::flattenSingleValue($text); $text = PHPExcel_Calculation_Functions::flattenSingleValue($text);
$fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText); $fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText);
$toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText); $toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText);
@ -549,7 +568,7 @@ class PHPExcel_Calculation_TextData {
} }
return $text; return $text;
} // function SUBSTITUTE() }
/** /**
@ -558,14 +577,15 @@ class PHPExcel_Calculation_TextData {
* @param mixed $testValue Value to check * @param mixed $testValue Value to check
* @return boolean * @return boolean
*/ */
public static function RETURNSTRING($testValue = '') { public static function RETURNSTRING($testValue = '')
{
$testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue); $testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue);
if (is_string($testValue)) { if (is_string($testValue)) {
return $testValue; return $testValue;
} }
return Null; return null;
} // function RETURNSTRING() }
/** /**
@ -575,7 +595,8 @@ class PHPExcel_Calculation_TextData {
* @param string $format Format mask to use * @param string $format Format mask to use
* @return boolean * @return boolean
*/ */
public static function TEXTFORMAT($value,$format) { public static function TEXTFORMAT($value, $format)
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$format = PHPExcel_Calculation_Functions::flattenSingleValue($format); $format = PHPExcel_Calculation_Functions::flattenSingleValue($format);
@ -584,7 +605,7 @@ class PHPExcel_Calculation_TextData {
} }
return (string) PHPExcel_Style_NumberFormat::toFormattedString($value, $format); return (string) PHPExcel_Style_NumberFormat::toFormattedString($value, $format);
} // function TEXTFORMAT() }
/** /**
* VALUE * VALUE
@ -592,7 +613,8 @@ class PHPExcel_Calculation_TextData {
* @param mixed $value Value to check * @param mixed $value Value to check
* @return boolean * @return boolean
*/ */
public static function VALUE($value = '') { public static function VALUE($value = '')
{
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value); $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
if (!is_numeric($value)) { if (!is_numeric($value)) {
@ -626,5 +648,4 @@ class PHPExcel_Calculation_TextData {
} }
return (float) $value; return (float) $value;
} }
} }

View File

@ -32,14 +32,14 @@ class PHPExcel_Calculation_Token_Stack
* *
* @var mixed[] * @var mixed[]
*/ */
private $_stack = array(); private $stack = array();
/** /**
* Count of entries in the parser stack * Count of entries in the parser stack
* *
* @var integer * @var integer
*/ */
private $_count = 0; private $count = 0;
/** /**
* Return the number of entries on the stack * Return the number of entries on the stack
@ -48,7 +48,7 @@ class PHPExcel_Calculation_Token_Stack
*/ */
public function count() public function count()
{ {
return $this->_count; return $this->count;
} }
/** /**
@ -60,7 +60,7 @@ class PHPExcel_Calculation_Token_Stack
*/ */
public function push($type, $value, $reference = null) public function push($type, $value, $reference = null)
{ {
$this->_stack[$this->_count++] = array( $this->stack[$this->count++] = array(
'type' => $type, 'type' => $type,
'value' => $value, 'value' => $value,
'reference' => $reference 'reference' => $reference
@ -68,7 +68,7 @@ class PHPExcel_Calculation_Token_Stack
if ($type == 'Function') { if ($type == 'Function') {
$localeFunction = PHPExcel_Calculation::_localeFunc($value); $localeFunction = PHPExcel_Calculation::_localeFunc($value);
if ($localeFunction != $value) { if ($localeFunction != $value) {
$this->_stack[($this->_count - 1)]['localeValue'] = $localeFunction; $this->stack[($this->count - 1)]['localeValue'] = $localeFunction;
} }
} }
} }
@ -80,8 +80,8 @@ class PHPExcel_Calculation_Token_Stack
*/ */
public function pop() public function pop()
{ {
if ($this->_count > 0) { if ($this->count > 0) {
return $this->_stack[--$this->_count]; return $this->stack[--$this->count];
} }
return null; return null;
} }
@ -94,18 +94,18 @@ class PHPExcel_Calculation_Token_Stack
*/ */
public function last($n = 1) public function last($n = 1)
{ {
if ($this->_count - $n < 0) { if ($this->count - $n < 0) {
return null; return null;
} }
return $this->_stack[$this->_count - $n]; return $this->stack[$this->count - $n];
} }
/** /**
* Clear the stack * Clear the stack
*/ */
function clear() public function clear()
{ {
$this->_stack = array(); $this->stack = array();
$this->_count = 0; $this->count = 0;
} }
} }