More PSR-2 adjustments
This commit is contained in:
parent
c07b54172a
commit
1efa7e8533
|
@ -1,6 +1,16 @@
|
|||
<?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
|
||||
*
|
||||
|
@ -24,28 +34,8 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
/** 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 {
|
||||
|
||||
|
||||
class PHPExcel_Calculation_LookupRef
|
||||
{
|
||||
/**
|
||||
* CELL_ADDRESS
|
||||
*
|
||||
|
@ -67,32 +57,43 @@ class PHPExcel_Calculation_LookupRef {
|
|||
* @param sheetText Optional Name of worksheet to use
|
||||
* @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);
|
||||
$column = PHPExcel_Calculation_Functions::flattenSingleValue($column);
|
||||
$relativity = PHPExcel_Calculation_Functions::flattenSingleValue($relativity);
|
||||
$sheetText = PHPExcel_Calculation_Functions::flattenSingleValue($sheetText);
|
||||
$column = PHPExcel_Calculation_Functions::flattenSingleValue($column);
|
||||
$relativity = PHPExcel_Calculation_Functions::flattenSingleValue($relativity);
|
||||
$sheetText = PHPExcel_Calculation_Functions::flattenSingleValue($sheetText);
|
||||
|
||||
if (($row < 1) || ($column < 1)) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
}
|
||||
|
||||
if ($sheetText > '') {
|
||||
if (strpos($sheetText,' ') !== False) { $sheetText = "'".$sheetText."'"; }
|
||||
if (strpos($sheetText, ' ') !== false) {
|
||||
$sheetText = "'".$sheetText."'";
|
||||
}
|
||||
$sheetText .='!';
|
||||
}
|
||||
if ((!is_bool($referenceStyle)) || $referenceStyle) {
|
||||
$rowRelative = $columnRelative = '$';
|
||||
$column = PHPExcel_Cell::stringFromColumnIndex($column-1);
|
||||
if (($relativity == 2) || ($relativity == 4)) { $columnRelative = ''; }
|
||||
if (($relativity == 3) || ($relativity == 4)) { $rowRelative = ''; }
|
||||
if (($relativity == 2) || ($relativity == 4)) {
|
||||
$columnRelative = '';
|
||||
}
|
||||
if (($relativity == 3) || ($relativity == 4)) {
|
||||
$rowRelative = '';
|
||||
}
|
||||
return $sheetText.$columnRelative.$column.$rowRelative.$row;
|
||||
} else {
|
||||
if (($relativity == 2) || ($relativity == 4)) { $column = '['.$column.']'; }
|
||||
if (($relativity == 3) || ($relativity == 4)) { $row = '['.$row.']'; }
|
||||
if (($relativity == 2) || ($relativity == 4)) {
|
||||
$column = '['.$column.']';
|
||||
}
|
||||
if (($relativity == 3) || ($relativity == 4)) {
|
||||
$row = '['.$row.']';
|
||||
}
|
||||
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
|
||||
* @return integer or array of integer
|
||||
*/
|
||||
public static function COLUMN($cellAddress=Null) {
|
||||
if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; }
|
||||
public static function COLUMN($cellAddress = null)
|
||||
{
|
||||
if (is_null($cellAddress) || trim($cellAddress) === '') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_array($cellAddress)) {
|
||||
foreach($cellAddress as $columnKey => $value) {
|
||||
$columnKey = preg_replace('/[^a-z]/i','',$columnKey);
|
||||
foreach ($cellAddress as $columnKey => $value) {
|
||||
$columnKey = preg_replace('/[^a-z]/i', '', $columnKey);
|
||||
return (integer) PHPExcel_Cell::columnIndexFromString($columnKey);
|
||||
}
|
||||
} else {
|
||||
if (strpos($cellAddress,'!') !== false) {
|
||||
list($sheet,$cellAddress) = explode('!',$cellAddress);
|
||||
if (strpos($cellAddress, '!') !== false) {
|
||||
list($sheet, $cellAddress) = explode('!', $cellAddress);
|
||||
}
|
||||
if (strpos($cellAddress,':') !== false) {
|
||||
list($startAddress,$endAddress) = explode(':',$cellAddress);
|
||||
$startAddress = preg_replace('/[^a-z]/i','',$startAddress);
|
||||
$endAddress = preg_replace('/[^a-z]/i','',$endAddress);
|
||||
if (strpos($cellAddress, ':') !== false) {
|
||||
list($startAddress, $endAddress) = explode(':', $cellAddress);
|
||||
$startAddress = preg_replace('/[^a-z]/i', '', $startAddress);
|
||||
$endAddress = preg_replace('/[^a-z]/i', '', $endAddress);
|
||||
$returnValue = array();
|
||||
do {
|
||||
$returnValue[] = (integer) PHPExcel_Cell::columnIndexFromString($startAddress);
|
||||
} while ($startAddress++ != $endAddress);
|
||||
return $returnValue;
|
||||
} else {
|
||||
$cellAddress = preg_replace('/[^a-z]/i','',$cellAddress);
|
||||
$cellAddress = preg_replace('/[^a-z]/i', '', $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
|
||||
* @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 === '') {
|
||||
return 1;
|
||||
} elseif (!is_array($cellAddress)) {
|
||||
|
@ -158,14 +163,14 @@ class PHPExcel_Calculation_LookupRef {
|
|||
|
||||
reset($cellAddress);
|
||||
$isMatrix = (is_numeric(key($cellAddress)));
|
||||
list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
|
||||
list($columns, $rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
|
||||
|
||||
if ($isMatrix) {
|
||||
return $rows;
|
||||
} else {
|
||||
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
|
||||
* @return integer or array of integer
|
||||
*/
|
||||
public static function ROW($cellAddress=Null) {
|
||||
if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; }
|
||||
public static function ROW($cellAddress = null)
|
||||
{
|
||||
if (is_null($cellAddress) || trim($cellAddress) === '') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_array($cellAddress)) {
|
||||
foreach($cellAddress as $columnKey => $rowValue) {
|
||||
foreach($rowValue as $rowKey => $cellValue) {
|
||||
return (integer) preg_replace('/[^0-9]/i','',$rowKey);
|
||||
foreach ($cellAddress as $columnKey => $rowValue) {
|
||||
foreach ($rowValue as $rowKey => $cellValue) {
|
||||
return (integer) preg_replace('/[^0-9]/i', '', $rowKey);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (strpos($cellAddress,'!') !== false) {
|
||||
list($sheet,$cellAddress) = explode('!',$cellAddress);
|
||||
if (strpos($cellAddress, '!') !== false) {
|
||||
list($sheet, $cellAddress) = explode('!', $cellAddress);
|
||||
}
|
||||
if (strpos($cellAddress,':') !== false) {
|
||||
list($startAddress,$endAddress) = explode(':',$cellAddress);
|
||||
$startAddress = preg_replace('/[^0-9]/','',$startAddress);
|
||||
$endAddress = preg_replace('/[^0-9]/','',$endAddress);
|
||||
if (strpos($cellAddress, ':') !== false) {
|
||||
list($startAddress, $endAddress) = explode(':', $cellAddress);
|
||||
$startAddress = preg_replace('/[^0-9]/', '', $startAddress);
|
||||
$endAddress = preg_replace('/[^0-9]/', '', $endAddress);
|
||||
$returnValue = array();
|
||||
do {
|
||||
$returnValue[][] = (integer) $startAddress;
|
||||
} while ($startAddress++ != $endAddress);
|
||||
return $returnValue;
|
||||
} else {
|
||||
list($cellAddress) = explode(':',$cellAddress);
|
||||
return (integer) preg_replace('/[^0-9]/','',$cellAddress);
|
||||
list($cellAddress) = explode(':', $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
|
||||
* @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 === '') {
|
||||
return 1;
|
||||
} elseif (!is_array($cellAddress)) {
|
||||
|
@ -232,14 +241,14 @@ class PHPExcel_Calculation_LookupRef {
|
|||
|
||||
reset($cellAddress);
|
||||
$isMatrix = (is_numeric(key($cellAddress)));
|
||||
list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
|
||||
list($columns, $rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
|
||||
|
||||
if ($isMatrix) {
|
||||
return $columns;
|
||||
} else {
|
||||
return $rows;
|
||||
}
|
||||
} // function ROWS()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -255,12 +264,13 @@ class PHPExcel_Calculation_LookupRef {
|
|||
* @param PHPExcel_Cell $pCell The cell to set the hyperlink in
|
||||
* @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();
|
||||
$pCell = array_pop($args);
|
||||
|
||||
$linkURL = (is_null($linkURL)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($linkURL);
|
||||
$displayName = (is_null($displayName)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($displayName);
|
||||
$linkURL = (is_null($linkURL)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($linkURL);
|
||||
$displayName = (is_null($displayName)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($displayName);
|
||||
|
||||
if ((!is_object($pCell)) || (trim($linkURL) == '')) {
|
||||
return PHPExcel_Calculation_Functions::REF();
|
||||
|
@ -273,7 +283,7 @@ class PHPExcel_Calculation_LookupRef {
|
|||
$pCell->getHyperlink()->setUrl($linkURL);
|
||||
|
||||
return $displayName;
|
||||
} // function HYPERLINK()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -294,16 +304,17 @@ class PHPExcel_Calculation_LookupRef {
|
|||
* @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);
|
||||
if (is_null($cellAddress) || $cellAddress === '') {
|
||||
return PHPExcel_Calculation_Functions::REF();
|
||||
}
|
||||
|
||||
$cellAddress1 = $cellAddress;
|
||||
$cellAddress2 = NULL;
|
||||
if (strpos($cellAddress,':') !== false) {
|
||||
list($cellAddress1,$cellAddress2) = explode(':',$cellAddress);
|
||||
$cellAddress2 = null;
|
||||
if (strpos($cellAddress, ':') !== false) {
|
||||
list($cellAddress1, $cellAddress2) = explode(':', $cellAddress);
|
||||
}
|
||||
|
||||
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress1, $matches)) ||
|
||||
|
@ -312,27 +323,27 @@ class PHPExcel_Calculation_LookupRef {
|
|||
return PHPExcel_Calculation_Functions::REF();
|
||||
}
|
||||
|
||||
if (strpos($cellAddress,'!') !== FALSE) {
|
||||
list($sheetName, $cellAddress) = explode('!',$cellAddress);
|
||||
if (strpos($cellAddress, '!') !== false) {
|
||||
list($sheetName, $cellAddress) = explode('!', $cellAddress);
|
||||
$sheetName = trim($sheetName, "'");
|
||||
$pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
|
||||
} else {
|
||||
$pSheet = $pCell->getWorksheet();
|
||||
}
|
||||
|
||||
return PHPExcel_Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, FALSE);
|
||||
return PHPExcel_Calculation::getInstance()->extractNamedRange($cellAddress, $pSheet, false);
|
||||
}
|
||||
|
||||
if (strpos($cellAddress,'!') !== FALSE) {
|
||||
list($sheetName,$cellAddress) = explode('!',$cellAddress);
|
||||
if (strpos($cellAddress, '!') !== false) {
|
||||
list($sheetName, $cellAddress) = explode('!', $cellAddress);
|
||||
$sheetName = trim($sheetName, "'");
|
||||
$pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
|
||||
} else {
|
||||
$pSheet = $pCell->getWorksheet();
|
||||
}
|
||||
|
||||
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, FALSE);
|
||||
} // function INDIRECT()
|
||||
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
* @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) {
|
||||
$rows = PHPExcel_Calculation_Functions::flattenSingleValue($rows);
|
||||
$columns = PHPExcel_Calculation_Functions::flattenSingleValue($columns);
|
||||
$height = PHPExcel_Calculation_Functions::flattenSingleValue($height);
|
||||
$width = PHPExcel_Calculation_Functions::flattenSingleValue($width);
|
||||
if ($cellAddress == Null) {
|
||||
public static function OFFSET($cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null)
|
||||
{
|
||||
$rows = PHPExcel_Calculation_Functions::flattenSingleValue($rows);
|
||||
$columns = PHPExcel_Calculation_Functions::flattenSingleValue($columns);
|
||||
$height = PHPExcel_Calculation_Functions::flattenSingleValue($height);
|
||||
$width = PHPExcel_Calculation_Functions::flattenSingleValue($width);
|
||||
if ($cellAddress == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -375,18 +387,18 @@ class PHPExcel_Calculation_LookupRef {
|
|||
return PHPExcel_Calculation_Functions::REF();
|
||||
}
|
||||
|
||||
$sheetName = NULL;
|
||||
if (strpos($cellAddress,"!")) {
|
||||
list($sheetName,$cellAddress) = explode("!",$cellAddress);
|
||||
$sheetName = null;
|
||||
if (strpos($cellAddress, "!")) {
|
||||
list($sheetName, $cellAddress) = explode("!", $cellAddress);
|
||||
$sheetName = trim($sheetName, "'");
|
||||
}
|
||||
if (strpos($cellAddress,":")) {
|
||||
list($startCell,$endCell) = explode(":",$cellAddress);
|
||||
if (strpos($cellAddress, ":")) {
|
||||
list($startCell, $endCell) = explode(":", $cellAddress);
|
||||
} else {
|
||||
$startCell = $endCell = $cellAddress;
|
||||
}
|
||||
list($startCellColumn,$startCellRow) = PHPExcel_Cell::coordinateFromString($startCell);
|
||||
list($endCellColumn,$endCellRow) = PHPExcel_Cell::coordinateFromString($endCell);
|
||||
list($startCellColumn, $startCellRow) = PHPExcel_Cell::coordinateFromString($startCell);
|
||||
list($endCellColumn, $endCellRow) = PHPExcel_Cell::coordinateFromString($endCell);
|
||||
|
||||
$startCellRow += $rows;
|
||||
$startCellColumn = PHPExcel_Cell::columnIndexFromString($startCellColumn) - 1;
|
||||
|
@ -419,14 +431,14 @@ class PHPExcel_Calculation_LookupRef {
|
|||
$cellAddress .= ':'.$endCellColumn.$endCellRow;
|
||||
}
|
||||
|
||||
if ($sheetName !== NULL) {
|
||||
if ($sheetName !== null) {
|
||||
$pSheet = $pCell->getWorksheet()->getParent()->getSheetByName($sheetName);
|
||||
} else {
|
||||
$pSheet = $pCell->getWorksheet();
|
||||
}
|
||||
|
||||
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False);
|
||||
} // function OFFSET()
|
||||
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -447,12 +459,13 @@ class PHPExcel_Calculation_LookupRef {
|
|||
* text.
|
||||
* @return mixed The selected value
|
||||
*/
|
||||
public static function CHOOSE() {
|
||||
public static function CHOOSE()
|
||||
{
|
||||
$chooseArgs = func_get_args();
|
||||
$chosenEntry = PHPExcel_Calculation_Functions::flattenArray(array_shift($chooseArgs));
|
||||
$entryCount = count($chooseArgs) - 1;
|
||||
|
||||
if(is_array($chosenEntry)) {
|
||||
if (is_array($chosenEntry)) {
|
||||
$chosenEntry = array_shift($chosenEntry);
|
||||
}
|
||||
if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) {
|
||||
|
@ -470,7 +483,7 @@ class PHPExcel_Calculation_LookupRef {
|
|||
} else {
|
||||
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.
|
||||
* @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_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
|
||||
$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
|
||||
foreach($lookup_array as $i => $lookupArrayValue) {
|
||||
foreach ($lookup_array as $i => $lookupArrayValue) {
|
||||
// check the type of the value
|
||||
if ((!is_numeric($lookupArrayValue)) && (!is_string($lookupArrayValue)) &&
|
||||
(!is_bool($lookupArrayValue)) && (!is_null($lookupArrayValue))) {
|
||||
|
@ -521,7 +535,7 @@ class PHPExcel_Calculation_LookupRef {
|
|||
$lookup_array[$i] = strtolower($lookupArrayValue);
|
||||
}
|
||||
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) {
|
||||
asort($lookup_array);
|
||||
$keySet = array_keys($lookup_array);
|
||||
} elseif($match_type == -1) {
|
||||
} elseif ($match_type == -1) {
|
||||
arsort($lookup_array);
|
||||
$keySet = array_keys($lookup_array);
|
||||
}
|
||||
|
@ -537,42 +551,25 @@ class PHPExcel_Calculation_LookupRef {
|
|||
// **
|
||||
// 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)) {
|
||||
// exact match
|
||||
return ++$i;
|
||||
} 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);
|
||||
// echo '$i='.$i.'<br />';
|
||||
$i = array_search($i, $keySet);
|
||||
// if match_type is -1 <=> find the smallest value that is greater than or equal to lookup_value
|
||||
if ($i < 1){
|
||||
// 1st cell was allready smaller than the lookup_value
|
||||
if ($i < 1) {
|
||||
// 1st cell was already smaller than the lookup_value
|
||||
break;
|
||||
} else {
|
||||
// the previous cell was the match
|
||||
return $keySet[$i-1]+1;
|
||||
}
|
||||
} 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);
|
||||
// echo '$i='.$i.'<br />';
|
||||
$i = array_search($i, $keySet);
|
||||
// if match_type is 1 <=> find the largest value that is less than or equal to lookup_value
|
||||
if ($i < 1){
|
||||
// 1st cell was allready bigger than the lookup_value
|
||||
if ($i < 1) {
|
||||
// 1st cell was already bigger than the lookup_value
|
||||
break;
|
||||
} else {
|
||||
// the previous cell was the match
|
||||
|
@ -583,7 +580,7 @@ class PHPExcel_Calculation_LookupRef {
|
|||
|
||||
// unsuccessful in finding a match, return #N/A error value
|
||||
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.
|
||||
* @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)) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
}
|
||||
|
@ -620,7 +617,7 @@ class PHPExcel_Calculation_LookupRef {
|
|||
}
|
||||
$rowNum = $rowKeys[--$rowNum];
|
||||
$returnArray = array();
|
||||
foreach($arrayValues as $arrayColumn) {
|
||||
foreach ($arrayValues as $arrayColumn) {
|
||||
if (is_array($arrayColumn)) {
|
||||
if (isset($arrayColumn[$rowNum])) {
|
||||
$returnArray[] = $arrayColumn[$rowNum];
|
||||
|
@ -642,7 +639,7 @@ class PHPExcel_Calculation_LookupRef {
|
|||
$rowNum = $rowKeys[--$rowNum];
|
||||
|
||||
return $arrayValues[$rowNum][$columnNum];
|
||||
} // function INDEX()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -653,43 +650,48 @@ 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.
|
||||
*/
|
||||
public static function TRANSPOSE($matrixData) {
|
||||
public static function TRANSPOSE($matrixData)
|
||||
{
|
||||
$returnMatrix = array();
|
||||
if (!is_array($matrixData)) { $matrixData = array(array($matrixData)); }
|
||||
if (!is_array($matrixData)) {
|
||||
$matrixData = array(array($matrixData));
|
||||
}
|
||||
|
||||
$column = 0;
|
||||
foreach($matrixData as $matrixRow) {
|
||||
foreach ($matrixData as $matrixRow) {
|
||||
$row = 0;
|
||||
foreach($matrixRow as $matrixCell) {
|
||||
foreach ($matrixRow as $matrixCell) {
|
||||
$returnMatrix[$row][$column] = $matrixCell;
|
||||
++$row;
|
||||
}
|
||||
++$column;
|
||||
}
|
||||
return $returnMatrix;
|
||||
} // function TRANSPOSE()
|
||||
}
|
||||
|
||||
|
||||
private static function _vlookupSort($a,$b) {
|
||||
private static function vlookupSort($a, $b)
|
||||
{
|
||||
reset($a);
|
||||
$firstColumn = key($a);
|
||||
if (strtolower($a[$firstColumn]) == strtolower($b[$firstColumn])) {
|
||||
return 0;
|
||||
}
|
||||
return (strtolower($a[$firstColumn]) < strtolower($b[$firstColumn])) ? -1 : 1;
|
||||
} // function _vlookupSort()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* VLOOKUP
|
||||
* The VLOOKUP function searches for value in the left-most column of lookup_array and returns the value in the same row based on the index_number.
|
||||
* @param lookup_value The value that you want to match in lookup_array
|
||||
* @param lookup_array The range of cells being searched
|
||||
* @param index_number The column number in table_array from which the matching value must be returned. The first column is 1.
|
||||
* @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
|
||||
*/
|
||||
public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match=true) {
|
||||
* VLOOKUP
|
||||
* The VLOOKUP function searches for value in the left-most column of lookup_array and returns the value in the same row based on the index_number.
|
||||
* @param lookup_value The value that you want to match in lookup_array
|
||||
* @param lookup_array The range of cells being searched
|
||||
* @param index_number The column number in table_array from which the matching value must be returned. The first column is 1.
|
||||
* @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
|
||||
*/
|
||||
public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true)
|
||||
{
|
||||
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
|
||||
$index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number);
|
||||
$not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match);
|
||||
|
@ -715,11 +717,11 @@ class PHPExcel_Calculation_LookupRef {
|
|||
}
|
||||
|
||||
if (!$not_exact_match) {
|
||||
uasort($lookup_array,array('self','_vlookupSort'));
|
||||
uasort($lookup_array, array('self', 'vlookupSort'));
|
||||
}
|
||||
|
||||
$rowNumber = $rowValue = False;
|
||||
foreach($lookup_array as $rowKey => $rowData) {
|
||||
$rowNumber = $rowValue = false;
|
||||
foreach ($lookup_array as $rowKey => $rowData) {
|
||||
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)))) {
|
||||
break;
|
||||
|
@ -739,19 +741,20 @@ class PHPExcel_Calculation_LookupRef {
|
|||
}
|
||||
|
||||
return PHPExcel_Calculation_Functions::NA();
|
||||
} // function VLOOKUP()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param lookup_value The value that you want to match in lookup_array
|
||||
* @param lookup_array The range of cells being searched
|
||||
* @param index_number The row number in table_array from which the matching value must be returned. The first row is 1.
|
||||
* @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
|
||||
*/
|
||||
public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match=true) {
|
||||
/**
|
||||
* 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.
|
||||
* @param lookup_value The value that you want to match in lookup_array
|
||||
* @param lookup_array The range of cells being searched
|
||||
* @param index_number The row number in table_array from which the matching value must be returned. The first row is 1.
|
||||
* @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
|
||||
*/
|
||||
public static function HLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match = true)
|
||||
{
|
||||
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
|
||||
$index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number);
|
||||
$not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match);
|
||||
|
@ -781,8 +784,8 @@ class PHPExcel_Calculation_LookupRef {
|
|||
$firstRowH = asort($lookup_array[$firstColumn]);
|
||||
}
|
||||
|
||||
$rowNumber = $rowValue = False;
|
||||
foreach($lookup_array[$firstColumn] as $rowKey => $rowData) {
|
||||
$rowNumber = $rowValue = false;
|
||||
foreach ($lookup_array[$firstColumn] as $rowKey => $rowData) {
|
||||
if ((is_numeric($lookup_value) && is_numeric($rowData) && ($rowData > $lookup_value)) ||
|
||||
(!is_numeric($lookup_value) && !is_numeric($rowData) && (strtolower($rowData) > strtolower($lookup_value)))) {
|
||||
break;
|
||||
|
@ -802,7 +805,7 @@ class PHPExcel_Calculation_LookupRef {
|
|||
}
|
||||
|
||||
return PHPExcel_Calculation_Functions::NA();
|
||||
} // function HLOOKUP()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -813,8 +816,9 @@ class PHPExcel_Calculation_LookupRef {
|
|||
* @param result_vector The column from which the matching value must be returned
|
||||
* @return mixed The value of the found cell
|
||||
*/
|
||||
public static function LOOKUP($lookup_value, $lookup_vector, $result_vector=null) {
|
||||
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
|
||||
public static function LOOKUP($lookup_value, $lookup_vector, $result_vector = null)
|
||||
{
|
||||
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
|
||||
|
||||
if (!is_array($lookup_vector)) {
|
||||
return PHPExcel_Calculation_Functions::NA();
|
||||
|
@ -849,7 +853,7 @@ class PHPExcel_Calculation_LookupRef {
|
|||
$lookup_vector = array_shift($lookup_vector);
|
||||
}
|
||||
if ($lookupColumns != 2) {
|
||||
foreach($lookup_vector as &$value) {
|
||||
foreach ($lookup_vector as &$value) {
|
||||
if (is_array($value)) {
|
||||
$k = array_keys($value);
|
||||
$key1 = $key2 = array_shift($k);
|
||||
|
@ -869,7 +873,6 @@ class PHPExcel_Calculation_LookupRef {
|
|||
unset($value);
|
||||
}
|
||||
|
||||
return self::VLOOKUP($lookup_value,$lookup_vector,2);
|
||||
} // function LOOKUP()
|
||||
|
||||
} // class PHPExcel_Calculation_LookupRef
|
||||
return self::VLOOKUP($lookup_value, $lookup_vector, 2);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,16 @@
|
|||
<?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
|
||||
*
|
||||
|
@ -24,46 +34,30 @@
|
|||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_Calculation_TextData
|
||||
{
|
||||
private static $invalidChars;
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @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)
|
||||
private static function unicodeToOrd($c)
|
||||
{
|
||||
if (ord($c{0}) >=0 && ord($c{0}) <= 127) {
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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 0;
|
||||
} // function _uniord()
|
||||
}
|
||||
|
||||
/**
|
||||
* CHARACTER
|
||||
|
@ -71,8 +65,9 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param string $character Value
|
||||
* @return int
|
||||
*/
|
||||
public static function CHARACTER($character) {
|
||||
$character = PHPExcel_Calculation_Functions::flattenSingleValue($character);
|
||||
public static function CHARACTER($character)
|
||||
{
|
||||
$character = PHPExcel_Calculation_Functions::flattenSingleValue($character);
|
||||
|
||||
if ((!is_numeric($character)) || ($character < 0)) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
|
@ -92,22 +87,23 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param mixed $stringValue Value to check
|
||||
* @return string
|
||||
*/
|
||||
public static function TRIMNONPRINTABLE($stringValue = '') {
|
||||
public static function TRIMNONPRINTABLE($stringValue = '')
|
||||
{
|
||||
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
|
||||
|
||||
if (is_bool($stringValue)) {
|
||||
return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
|
||||
}
|
||||
|
||||
if (self::$_invalidChars == Null) {
|
||||
self::$_invalidChars = range(chr(0),chr(31));
|
||||
if (self::$invalidChars == null) {
|
||||
self::$invalidChars = range(chr(0), chr(31));
|
||||
}
|
||||
|
||||
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;
|
||||
} // function TRIMNONPRINTABLE()
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -116,17 +112,18 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param mixed $stringValue Value to check
|
||||
* @return string
|
||||
*/
|
||||
public static function TRIMSPACES($stringValue = '') {
|
||||
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
|
||||
public static function TRIMSPACES($stringValue = '')
|
||||
{
|
||||
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
|
||||
if (is_bool($stringValue)) {
|
||||
return ($stringValue) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
|
||||
}
|
||||
|
||||
if (is_string($stringValue) || is_numeric($stringValue)) {
|
||||
return trim(preg_replace('/ +/',' ',trim($stringValue, ' ')), ' ');
|
||||
return trim(preg_replace('/ +/', ' ', trim($stringValue, ' ')), ' ');
|
||||
}
|
||||
return NULL;
|
||||
} // function TRIMSPACES()
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -135,9 +132,11 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param string $characters Value
|
||||
* @return int
|
||||
*/
|
||||
public static function ASCIICODE($characters) {
|
||||
if (($characters === NULL) || ($characters === ''))
|
||||
public static function ASCIICODE($characters)
|
||||
{
|
||||
if (($characters === null) || ($characters === '')) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
}
|
||||
$characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters);
|
||||
if (is_bool($characters)) {
|
||||
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
|
||||
|
@ -149,13 +148,17 @@ class PHPExcel_Calculation_TextData {
|
|||
|
||||
$character = $characters;
|
||||
if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) {
|
||||
if (mb_strlen($characters, 'UTF-8') > 1) { $character = mb_substr($characters, 0, 1, 'UTF-8'); }
|
||||
return self::_uniord($character);
|
||||
if (mb_strlen($characters, 'UTF-8') > 1) {
|
||||
$character = mb_substr($characters, 0, 1, 'UTF-8');
|
||||
}
|
||||
return self::unicodeToOrd($character);
|
||||
} else {
|
||||
if (strlen($characters) > 0) { $character = substr($characters, 0, 1); }
|
||||
if (strlen($characters) > 0) {
|
||||
$character = substr($characters, 0, 1);
|
||||
}
|
||||
return ord($character);
|
||||
}
|
||||
} // function ASCIICODE()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -163,8 +166,8 @@ class PHPExcel_Calculation_TextData {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function CONCATENATE() {
|
||||
// Return value
|
||||
public static function CONCATENATE()
|
||||
{
|
||||
$returnValue = '';
|
||||
|
||||
// Loop through arguments
|
||||
|
@ -180,9 +183,8 @@ class PHPExcel_Calculation_TextData {
|
|||
$returnValue .= $arg;
|
||||
}
|
||||
|
||||
// Return
|
||||
return $returnValue;
|
||||
} // function CONCATENATE()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -197,7 +199,8 @@ class PHPExcel_Calculation_TextData {
|
|||
* If you omit decimals, it is assumed to be 2
|
||||
* @return string
|
||||
*/
|
||||
public static function DOLLAR($value = 0, $decimals = 2) {
|
||||
public static function DOLLAR($value = 0, $decimals = 2)
|
||||
{
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
|
||||
|
||||
|
@ -209,16 +212,18 @@ class PHPExcel_Calculation_TextData {
|
|||
|
||||
$mask = '$#,##0';
|
||||
if ($decimals > 0) {
|
||||
$mask .= '.' . str_repeat('0',$decimals);
|
||||
$mask .= '.' . str_repeat('0', $decimals);
|
||||
} else {
|
||||
$round = pow(10,abs($decimals));
|
||||
if ($value < 0) { $round = 0-$round; }
|
||||
$round = pow(10, abs($decimals));
|
||||
if ($value < 0) {
|
||||
$round = 0-$round;
|
||||
}
|
||||
$value = PHPExcel_Calculation_MathTrig::MROUND($value, $round);
|
||||
}
|
||||
|
||||
return PHPExcel_Style_NumberFormat::toFormattedString($value, $mask);
|
||||
|
||||
} // function DOLLAR()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -229,10 +234,11 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param int $offset Offset within $haystack
|
||||
* @return string
|
||||
*/
|
||||
public static function SEARCHSENSITIVE($needle,$haystack,$offset=1) {
|
||||
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle);
|
||||
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack);
|
||||
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset);
|
||||
public static function SEARCHSENSITIVE($needle, $haystack, $offset = 1)
|
||||
{
|
||||
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle);
|
||||
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack);
|
||||
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset);
|
||||
|
||||
if (!is_bool($needle)) {
|
||||
if (is_bool($haystack)) {
|
||||
|
@ -254,7 +260,7 @@ class PHPExcel_Calculation_TextData {
|
|||
}
|
||||
}
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
} // function SEARCHSENSITIVE()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -265,10 +271,11 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param int $offset Offset within $haystack
|
||||
* @return string
|
||||
*/
|
||||
public static function SEARCHINSENSITIVE($needle,$haystack,$offset=1) {
|
||||
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle);
|
||||
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack);
|
||||
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset);
|
||||
public static function SEARCHINSENSITIVE($needle, $haystack, $offset = 1)
|
||||
{
|
||||
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle);
|
||||
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack);
|
||||
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset);
|
||||
|
||||
if (!is_bool($needle)) {
|
||||
if (is_bool($haystack)) {
|
||||
|
@ -280,7 +287,7 @@ class PHPExcel_Calculation_TextData {
|
|||
return $offset;
|
||||
}
|
||||
if (function_exists('mb_stripos')) {
|
||||
$pos = mb_stripos($haystack, $needle, --$offset,'UTF-8');
|
||||
$pos = mb_stripos($haystack, $needle, --$offset, 'UTF-8');
|
||||
} else {
|
||||
$pos = stripos($haystack, $needle, --$offset);
|
||||
}
|
||||
|
@ -290,7 +297,7 @@ class PHPExcel_Calculation_TextData {
|
|||
}
|
||||
}
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
} // function SEARCHINSENSITIVE()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -301,10 +308,11 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param boolean $no_commas
|
||||
* @return boolean
|
||||
*/
|
||||
public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = FALSE) {
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
|
||||
$no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas);
|
||||
public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = false)
|
||||
{
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
|
||||
$no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas);
|
||||
|
||||
// Validate parameters
|
||||
if (!is_numeric($value) || !is_numeric($decimals)) {
|
||||
|
@ -312,14 +320,16 @@ class PHPExcel_Calculation_TextData {
|
|||
}
|
||||
$decimals = floor($decimals);
|
||||
|
||||
$valueResult = round($value,$decimals);
|
||||
if ($decimals < 0) { $decimals = 0; }
|
||||
$valueResult = round($value, $decimals);
|
||||
if ($decimals < 0) {
|
||||
$decimals = 0;
|
||||
}
|
||||
if (!$no_commas) {
|
||||
$valueResult = number_format($valueResult,$decimals);
|
||||
$valueResult = number_format($valueResult, $decimals);
|
||||
}
|
||||
|
||||
return (string) $valueResult;
|
||||
} // function FIXEDFORMAT()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -329,9 +339,10 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param int $chars Number of characters
|
||||
* @return string
|
||||
*/
|
||||
public static function LEFT($value = '', $chars = 1) {
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
|
||||
public static function LEFT($value = '', $chars = 1)
|
||||
{
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
|
||||
|
||||
if ($chars < 0) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
|
@ -346,7 +357,7 @@ class PHPExcel_Calculation_TextData {
|
|||
} else {
|
||||
return substr($value, 0, $chars);
|
||||
}
|
||||
} // function LEFT()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -357,10 +368,11 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param int $chars Number of characters
|
||||
* @return string
|
||||
*/
|
||||
public static function MID($value = '', $start = 1, $chars = null) {
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start);
|
||||
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
|
||||
public static function MID($value = '', $start = 1, $chars = null)
|
||||
{
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start);
|
||||
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
|
||||
|
||||
if (($start < 1) || ($chars < 0)) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
|
@ -375,7 +387,7 @@ class PHPExcel_Calculation_TextData {
|
|||
} else {
|
||||
return substr($value, --$start, $chars);
|
||||
}
|
||||
} // function MID()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -385,9 +397,10 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param int $chars Number of characters
|
||||
* @return string
|
||||
*/
|
||||
public static function RIGHT($value = '', $chars = 1) {
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
|
||||
public static function RIGHT($value = '', $chars = 1)
|
||||
{
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
|
||||
|
||||
if ($chars < 0) {
|
||||
return PHPExcel_Calculation_Functions::VALUE();
|
||||
|
@ -402,7 +415,7 @@ class PHPExcel_Calculation_TextData {
|
|||
} else {
|
||||
return substr($value, strlen($value) - $chars);
|
||||
}
|
||||
} // function RIGHT()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -411,8 +424,9 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param string $value Value
|
||||
* @return string
|
||||
*/
|
||||
public static function STRINGLENGTH($value = '') {
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
public static function STRINGLENGTH($value = '')
|
||||
{
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
|
||||
if (is_bool($value)) {
|
||||
$value = ($value) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
|
||||
|
@ -423,7 +437,7 @@ class PHPExcel_Calculation_TextData {
|
|||
} else {
|
||||
return strlen($value);
|
||||
}
|
||||
} // function STRINGLENGTH()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -434,15 +448,16 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param string $mixedCaseString
|
||||
* @return string
|
||||
*/
|
||||
public static function LOWERCASE($mixedCaseString) {
|
||||
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
|
||||
public static function LOWERCASE($mixedCaseString)
|
||||
{
|
||||
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
|
||||
|
||||
if (is_bool($mixedCaseString)) {
|
||||
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
|
||||
}
|
||||
|
||||
return PHPExcel_Shared_String::StrToLower($mixedCaseString);
|
||||
} // function LOWERCASE()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -453,15 +468,16 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param string $mixedCaseString
|
||||
* @return string
|
||||
*/
|
||||
public static function UPPERCASE($mixedCaseString) {
|
||||
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
|
||||
public static function UPPERCASE($mixedCaseString)
|
||||
{
|
||||
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
|
||||
|
||||
if (is_bool($mixedCaseString)) {
|
||||
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
|
||||
}
|
||||
|
||||
return PHPExcel_Shared_String::StrToUpper($mixedCaseString);
|
||||
} // function UPPERCASE()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -472,15 +488,16 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param string $mixedCaseString
|
||||
* @return string
|
||||
*/
|
||||
public static function PROPERCASE($mixedCaseString) {
|
||||
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
|
||||
public static function PROPERCASE($mixedCaseString)
|
||||
{
|
||||
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
|
||||
|
||||
if (is_bool($mixedCaseString)) {
|
||||
$mixedCaseString = ($mixedCaseString) ? PHPExcel_Calculation::getTRUE() : PHPExcel_Calculation::getFALSE();
|
||||
}
|
||||
|
||||
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
|
||||
* @return string
|
||||
*/
|
||||
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) {
|
||||
$oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText);
|
||||
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start);
|
||||
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
|
||||
$newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText);
|
||||
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText)
|
||||
{
|
||||
$oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText);
|
||||
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start);
|
||||
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
|
||||
$newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText);
|
||||
|
||||
$left = self::LEFT($oldText,$start-1);
|
||||
$right = self::RIGHT($oldText,self::STRINGLENGTH($oldText)-($start+$chars)+1);
|
||||
$left = self::LEFT($oldText, $start-1);
|
||||
$right = self::RIGHT($oldText, self::STRINGLENGTH($oldText)-($start+$chars)+1);
|
||||
|
||||
return $left.$newText.$right;
|
||||
} // function REPLACE()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -514,21 +532,22 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param integer $instance Instance Number
|
||||
* @return string
|
||||
*/
|
||||
public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) {
|
||||
$text = PHPExcel_Calculation_Functions::flattenSingleValue($text);
|
||||
$fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText);
|
||||
$toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText);
|
||||
$instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance));
|
||||
public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0)
|
||||
{
|
||||
$text = PHPExcel_Calculation_Functions::flattenSingleValue($text);
|
||||
$fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText);
|
||||
$toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText);
|
||||
$instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance));
|
||||
|
||||
if ($instance == 0) {
|
||||
if(function_exists('mb_str_replace')) {
|
||||
return mb_str_replace($fromText,$toText,$text);
|
||||
if (function_exists('mb_str_replace')) {
|
||||
return mb_str_replace($fromText, $toText, $text);
|
||||
} else {
|
||||
return str_replace($fromText,$toText,$text);
|
||||
return str_replace($fromText, $toText, $text);
|
||||
}
|
||||
} else {
|
||||
$pos = -1;
|
||||
while($instance > 0) {
|
||||
while ($instance > 0) {
|
||||
if (function_exists('mb_strpos')) {
|
||||
$pos = mb_strpos($text, $fromText, $pos+1, 'UTF-8');
|
||||
} else {
|
||||
|
@ -541,15 +560,15 @@ class PHPExcel_Calculation_TextData {
|
|||
}
|
||||
if ($pos !== false) {
|
||||
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 {
|
||||
return self::REPLACE($text,++$pos,strlen($fromText),$toText);
|
||||
return self::REPLACE($text, ++$pos, strlen($fromText), $toText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
} // function SUBSTITUTE()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -558,14 +577,15 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param mixed $testValue Value to check
|
||||
* @return boolean
|
||||
*/
|
||||
public static function RETURNSTRING($testValue = '') {
|
||||
$testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue);
|
||||
public static function RETURNSTRING($testValue = '')
|
||||
{
|
||||
$testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue);
|
||||
|
||||
if (is_string($testValue)) {
|
||||
return $testValue;
|
||||
}
|
||||
return Null;
|
||||
} // function RETURNSTRING()
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -575,16 +595,17 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param string $format Format mask to use
|
||||
* @return boolean
|
||||
*/
|
||||
public static function TEXTFORMAT($value,$format) {
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$format = PHPExcel_Calculation_Functions::flattenSingleValue($format);
|
||||
public static function TEXTFORMAT($value, $format)
|
||||
{
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
$format = PHPExcel_Calculation_Functions::flattenSingleValue($format);
|
||||
|
||||
if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) {
|
||||
$value = PHPExcel_Calculation_DateTime::DATEVALUE($value);
|
||||
}
|
||||
|
||||
return (string) PHPExcel_Style_NumberFormat::toFormattedString($value,$format);
|
||||
} // function TEXTFORMAT()
|
||||
return (string) PHPExcel_Style_NumberFormat::toFormattedString($value, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* VALUE
|
||||
|
@ -592,8 +613,9 @@ class PHPExcel_Calculation_TextData {
|
|||
* @param mixed $value Value to check
|
||||
* @return boolean
|
||||
*/
|
||||
public static function VALUE($value = '') {
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
public static function VALUE($value = '')
|
||||
{
|
||||
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
|
||||
|
||||
if (!is_numeric($value)) {
|
||||
$numberValue = str_replace(
|
||||
|
@ -626,5 +648,4 @@ class PHPExcel_Calculation_TextData {
|
|||
}
|
||||
return (float) $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,14 +32,14 @@ class PHPExcel_Calculation_Token_Stack
|
|||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
private $_stack = array();
|
||||
private $stack = array();
|
||||
|
||||
/**
|
||||
* Count of entries in the parser stack
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $_count = 0;
|
||||
private $count = 0;
|
||||
|
||||
/**
|
||||
* Return the number of entries on the stack
|
||||
|
@ -48,7 +48,7 @@ class PHPExcel_Calculation_Token_Stack
|
|||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->_count;
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,15 +60,15 @@ class PHPExcel_Calculation_Token_Stack
|
|||
*/
|
||||
public function push($type, $value, $reference = null)
|
||||
{
|
||||
$this->_stack[$this->_count++] = array(
|
||||
'type' => $type,
|
||||
'value' => $value,
|
||||
'reference' => $reference
|
||||
$this->stack[$this->count++] = array(
|
||||
'type' => $type,
|
||||
'value' => $value,
|
||||
'reference' => $reference
|
||||
);
|
||||
if ($type == 'Function') {
|
||||
$localeFunction = PHPExcel_Calculation::_localeFunc($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()
|
||||
{
|
||||
if ($this->_count > 0) {
|
||||
return $this->_stack[--$this->_count];
|
||||
if ($this->count > 0) {
|
||||
return $this->stack[--$this->count];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -94,18 +94,18 @@ class PHPExcel_Calculation_Token_Stack
|
|||
*/
|
||||
public function last($n = 1)
|
||||
{
|
||||
if ($this->_count - $n < 0) {
|
||||
if ($this->count - $n < 0) {
|
||||
return null;
|
||||
}
|
||||
return $this->_stack[$this->_count - $n];
|
||||
return $this->stack[$this->count - $n];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the stack
|
||||
*/
|
||||
function clear()
|
||||
public function clear()
|
||||
{
|
||||
$this->_stack = array();
|
||||
$this->_count = 0;
|
||||
$this->stack = array();
|
||||
$this->count = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue