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')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/** /**
* PHPExcel * 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,33 +110,36 @@ 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) {
$columnKey = preg_replace('/[^a-z]/i','',$columnKey); $columnKey = preg_replace('/[^a-z]/i', '', $columnKey);
return (integer) PHPExcel_Cell::columnIndexFromString($columnKey); return (integer) PHPExcel_Cell::columnIndexFromString($columnKey);
} }
} else { } else {
if (strpos($cellAddress,'!') !== false) { if (strpos($cellAddress, '!') !== false) {
list($sheet,$cellAddress) = explode('!',$cellAddress); list($sheet, $cellAddress) = explode('!', $cellAddress);
} }
if (strpos($cellAddress,':') !== false) { if (strpos($cellAddress, ':') !== false) {
list($startAddress,$endAddress) = explode(':',$cellAddress); list($startAddress, $endAddress) = explode(':', $cellAddress);
$startAddress = preg_replace('/[^a-z]/i','',$startAddress); $startAddress = preg_replace('/[^a-z]/i', '', $startAddress);
$endAddress = preg_replace('/[^a-z]/i','',$endAddress); $endAddress = preg_replace('/[^a-z]/i', '', $endAddress);
$returnValue = array(); $returnValue = array();
do { do {
$returnValue[] = (integer) PHPExcel_Cell::columnIndexFromString($startAddress); $returnValue[] = (integer) PHPExcel_Cell::columnIndexFromString($startAddress);
} while ($startAddress++ != $endAddress); } while ($startAddress++ != $endAddress);
return $returnValue; return $returnValue;
} else { } else {
$cellAddress = preg_replace('/[^a-z]/i','',$cellAddress); $cellAddress = preg_replace('/[^a-z]/i', '', $cellAddress);
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)) {
@ -158,14 +163,14 @@ class PHPExcel_Calculation_LookupRef {
reset($cellAddress); reset($cellAddress);
$isMatrix = (is_numeric(key($cellAddress))); $isMatrix = (is_numeric(key($cellAddress)));
list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress); list($columns, $rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
if ($isMatrix) { if ($isMatrix) {
return $rows; return $rows;
} else { } else {
return $columns; return $columns;
} }
} // function COLUMNS() }
/** /**
@ -182,34 +187,37 @@ 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) {
foreach($rowValue as $rowKey => $cellValue) { foreach ($rowValue as $rowKey => $cellValue) {
return (integer) preg_replace('/[^0-9]/i','',$rowKey); return (integer) preg_replace('/[^0-9]/i', '', $rowKey);
} }
} }
} else { } else {
if (strpos($cellAddress,'!') !== false) { if (strpos($cellAddress, '!') !== false) {
list($sheet,$cellAddress) = explode('!',$cellAddress); list($sheet, $cellAddress) = explode('!', $cellAddress);
} }
if (strpos($cellAddress,':') !== false) { if (strpos($cellAddress, ':') !== false) {
list($startAddress,$endAddress) = explode(':',$cellAddress); list($startAddress, $endAddress) = explode(':', $cellAddress);
$startAddress = preg_replace('/[^0-9]/','',$startAddress); $startAddress = preg_replace('/[^0-9]/', '', $startAddress);
$endAddress = preg_replace('/[^0-9]/','',$endAddress); $endAddress = preg_replace('/[^0-9]/', '', $endAddress);
$returnValue = array(); $returnValue = array();
do { do {
$returnValue[][] = (integer) $startAddress; $returnValue[][] = (integer) $startAddress;
} while ($startAddress++ != $endAddress); } while ($startAddress++ != $endAddress);
return $returnValue; return $returnValue;
} else { } else {
list($cellAddress) = explode(':',$cellAddress); list($cellAddress) = explode(':', $cellAddress);
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)) {
@ -232,14 +241,14 @@ class PHPExcel_Calculation_LookupRef {
reset($cellAddress); reset($cellAddress);
$isMatrix = (is_numeric(key($cellAddress))); $isMatrix = (is_numeric(key($cellAddress)));
list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress); list($columns, $rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
if ($isMatrix) { if ($isMatrix) {
return $columns; return $columns;
} 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,16 +304,17 @@ 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);
} }
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress1, $matches)) || if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress1, $matches)) ||
@ -312,27 +323,27 @@ 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);
} else { } else {
$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);
} 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 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,18 +387,18 @@ 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, "'");
} }
if (strpos($cellAddress,":")) { if (strpos($cellAddress, ":")) {
list($startCell,$endCell) = explode(":",$cellAddress); list($startCell, $endCell) = explode(":", $cellAddress);
} else { } else {
$startCell = $endCell = $cellAddress; $startCell = $endCell = $cellAddress;
} }
list($startCellColumn,$startCellRow) = PHPExcel_Cell::coordinateFromString($startCell); list($startCellColumn, $startCellRow) = PHPExcel_Cell::coordinateFromString($startCell);
list($endCellColumn,$endCellRow) = PHPExcel_Cell::coordinateFromString($endCell); list($endCellColumn, $endCellRow) = PHPExcel_Cell::coordinateFromString($endCell);
$startCellRow += $rows; $startCellRow += $rows;
$startCellColumn = PHPExcel_Cell::columnIndexFromString($startCellColumn) - 1; $startCellColumn = PHPExcel_Cell::columnIndexFromString($startCellColumn) - 1;
@ -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,12 +459,13 @@ 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;
if(is_array($chosenEntry)) { if (is_array($chosenEntry)) {
$chosenEntry = array_shift($chosenEntry); $chosenEntry = array_shift($chosenEntry);
} }
if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) { if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) {
@ -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);
@ -510,7 +524,7 @@ class PHPExcel_Calculation_LookupRef {
} }
// lookup_array should contain only number, text, or logical values, or empty (null) cells // lookup_array should contain only number, text, or logical values, or empty (null) cells
foreach($lookup_array as $i => $lookupArrayValue) { foreach ($lookup_array as $i => $lookupArrayValue) {
// check the type of the value // check the type of the value
if ((!is_numeric($lookupArrayValue)) && (!is_string($lookupArrayValue)) && if ((!is_numeric($lookupArrayValue)) && (!is_string($lookupArrayValue)) &&
(!is_bool($lookupArrayValue)) && (!is_null($lookupArrayValue))) { (!is_bool($lookupArrayValue)) && (!is_null($lookupArrayValue))) {
@ -521,7 +535,7 @@ class PHPExcel_Calculation_LookupRef {
$lookup_array[$i] = strtolower($lookupArrayValue); $lookup_array[$i] = strtolower($lookupArrayValue);
} }
if ((is_null($lookupArrayValue)) && (($match_type == 1) || ($match_type == -1))) { if ((is_null($lookupArrayValue)) && (($match_type == 1) || ($match_type == -1))) {
$lookup_array = array_slice($lookup_array,0,$i-1); $lookup_array = array_slice($lookup_array, 0, $i-1);
} }
} }
@ -529,7 +543,7 @@ class PHPExcel_Calculation_LookupRef {
if ($match_type == 1) { if ($match_type == 1) {
asort($lookup_array); asort($lookup_array);
$keySet = array_keys($lookup_array); $keySet = array_keys($lookup_array);
} elseif($match_type == -1) { } elseif ($match_type == -1) {
arsort($lookup_array); arsort($lookup_array);
$keySet = array_keys($lookup_array); $keySet = array_keys($lookup_array);
} }
@ -537,42 +551,25 @@ class PHPExcel_Calculation_LookupRef {
// ** // **
// find the match // find the match
// ** // **
// loop on the cells foreach ($lookup_array as $i => $lookupArrayValue) {
// var_dump($lookup_array);
// echo '<br />';
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.' => '; $i = array_search($i, $keySet);
// var_dump($lookupArrayValue);
// echo '<br />';
// echo 'Keyset = ';
// var_dump($keySet);
// echo '<br />';
$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.' => '; $i = array_search($i, $keySet);
// var_dump($lookupArrayValue);
// echo '<br />';
// echo 'Keyset = ';
// var_dump($keySet);
// echo '<br />';
$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();
} }
@ -620,7 +617,7 @@ class PHPExcel_Calculation_LookupRef {
} }
$rowNum = $rowKeys[--$rowNum]; $rowNum = $rowKeys[--$rowNum];
$returnArray = array(); $returnArray = array();
foreach($arrayValues as $arrayColumn) { foreach ($arrayValues as $arrayColumn) {
if (is_array($arrayColumn)) { if (is_array($arrayColumn)) {
if (isset($arrayColumn[$rowNum])) { if (isset($arrayColumn[$rowNum])) {
$returnArray[] = $arrayColumn[$rowNum]; $returnArray[] = $arrayColumn[$rowNum];
@ -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,31 +650,35 @@ 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) {
$row = 0; $row = 0;
foreach($matrixRow as $matrixCell) { foreach ($matrixRow as $matrixCell) {
$returnMatrix[$row][$column] = $matrixCell; $returnMatrix[$row][$column] = $matrixCell;
++$row; ++$row;
} }
++$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,11 +717,11 @@ 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)))) {
break; break;
@ -739,10 +741,10 @@ class PHPExcel_Calculation_LookupRef {
} }
return PHPExcel_Calculation_Functions::NA(); return PHPExcel_Calculation_Functions::NA();
} // function VLOOKUP() }
/** /**
* HLOOKUP * HLOOKUP
* The HLOOKUP function searches for value in the top-most row of lookup_array and returns the value in the same column based on the index_number. * The HLOOKUP function searches for value in the top-most row of lookup_array and returns the value in the same column based on the index_number.
* @param lookup_value The value that you want to match in lookup_array * @param lookup_value The value that you want to match in lookup_array
@ -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,8 +784,8 @@ 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)))) {
break; break;
@ -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)) {
@ -849,7 +853,7 @@ class PHPExcel_Calculation_LookupRef {
$lookup_vector = array_shift($lookup_vector); $lookup_vector = array_shift($lookup_vector);
} }
if ($lookupColumns != 2) { if ($lookupColumns != 2) {
foreach($lookup_vector as &$value) { foreach ($lookup_vector as &$value) {
if (is_array($value)) { if (is_array($value)) {
$k = array_keys($value); $k = array_keys($value);
$key1 = $key2 = array_shift($k); $key1 = $key2 = array_shift($k);
@ -869,7 +873,6 @@ class PHPExcel_Calculation_LookupRef {
unset($value); unset($value);
} }
return self::VLOOKUP($lookup_value,$lookup_vector,2); return self::VLOOKUP($lookup_value, $lookup_vector, 2);
} // function LOOKUP() }
}
} // class PHPExcel_Calculation_LookupRef

File diff suppressed because it is too large Load Diff

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')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/** /**
* PHPExcel * 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,17 +112,18 @@ 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();
} }
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);
@ -209,16 +212,18 @@ class PHPExcel_Calculation_TextData {
$mask = '$#,##0'; $mask = '$#,##0';
if ($decimals > 0) { if ($decimals > 0) {
$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);
@ -280,7 +287,7 @@ class PHPExcel_Calculation_TextData {
return $offset; return $offset;
} }
if (function_exists('mb_stripos')) { if (function_exists('mb_stripos')) {
$pos = mb_stripos($haystack, $needle, --$offset,'UTF-8'); $pos = mb_stripos($haystack, $needle, --$offset, 'UTF-8');
} else { } else {
$pos = stripos($haystack, $needle, --$offset); $pos = stripos($haystack, $needle, --$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);
@ -312,14 +320,16 @@ 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,17 +509,18 @@ 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);
$newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText); $newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText);
$left = self::LEFT($oldText,$start-1); $left = self::LEFT($oldText, $start-1);
$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,21 +532,22 @@ 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);
$instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance)); $instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance));
if ($instance == 0) { if ($instance == 0) {
if(function_exists('mb_str_replace')) { if (function_exists('mb_str_replace')) {
return mb_str_replace($fromText,$toText,$text); return mb_str_replace($fromText, $toText, $text);
} else { } else {
return str_replace($fromText,$toText,$text); return str_replace($fromText, $toText, $text);
} }
} else { } else {
$pos = -1; $pos = -1;
while($instance > 0) { while ($instance > 0) {
if (function_exists('mb_strpos')) { if (function_exists('mb_strpos')) {
$pos = mb_strpos($text, $fromText, $pos+1, 'UTF-8'); $pos = mb_strpos($text, $fromText, $pos+1, 'UTF-8');
} else { } else {
@ -541,15 +560,15 @@ class PHPExcel_Calculation_TextData {
} }
if ($pos !== false) { if ($pos !== false) {
if (function_exists('mb_strlen')) { if (function_exists('mb_strlen')) {
return self::REPLACE($text,++$pos,mb_strlen($fromText, 'UTF-8'),$toText); return self::REPLACE($text, ++$pos, mb_strlen($fromText, 'UTF-8'), $toText);
} else { } else {
return self::REPLACE($text,++$pos,strlen($fromText),$toText); return self::REPLACE($text, ++$pos, strlen($fromText), $toText);
} }
} }
} }
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);
@ -583,8 +604,8 @@ class PHPExcel_Calculation_TextData {
$value = PHPExcel_Calculation_DateTime::DATEVALUE($value); $value = PHPExcel_Calculation_DateTime::DATEVALUE($value);
} }
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;
} }
} }