当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPExcel_Calculation_Functions::REF方法代码示例

本文整理汇总了PHP中PHPExcel_Calculation_Functions::REF方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Calculation_Functions::REF方法的具体用法?PHP PHPExcel_Calculation_Functions::REF怎么用?PHP PHPExcel_Calculation_Functions::REF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPExcel_Calculation_Functions的用法示例。


在下文中一共展示了PHPExcel_Calculation_Functions::REF方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: VLOOKUP

 /**
  * 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);
     // index_number must be greater than or equal to 1
     if ($index_number < 1) {
         return PHPExcel_Calculation_Functions::VALUE();
     }
     // index_number must be less than or equal to the number of columns in lookup_array
     if (!is_array($lookup_array) || count($lookup_array) < 1) {
         return PHPExcel_Calculation_Functions::REF();
     } else {
         $f = array_keys($lookup_array);
         $firstRow = array_pop($f);
         if (!is_array($lookup_array[$firstRow]) || $index_number > count($lookup_array[$firstRow])) {
             return PHPExcel_Calculation_Functions::REF();
         } else {
             $columnKeys = array_keys($lookup_array[$firstRow]);
             $returnColumn = $columnKeys[--$index_number];
             $firstColumn = array_shift($columnKeys);
         }
     }
     if (!$not_exact_match) {
         uasort($lookup_array, array('self', '_vlookupSort'));
     }
     $rowNumber = $rowValue = False;
     foreach ($lookup_array as $rowKey => $rowData) {
         if (strtolower($rowData[$firstColumn]) > strtolower($lookup_value)) {
             break;
         }
         $rowNumber = $rowKey;
         $rowValue = $rowData[$firstColumn];
     }
     if ($rowNumber !== false) {
         if (!$not_exact_match && $rowValue != $lookup_value) {
             //	if an exact match is required, we have what we need to return an appropriate response
             return PHPExcel_Calculation_Functions::NA();
         } else {
             //	otherwise return the appropriate value
             return $lookup_array[$rowNumber][$returnColumn];
         }
     }
     return PHPExcel_Calculation_Functions::NA();
 }
开发者ID:Arikito,项目名称:webking.xt,代码行数:54,代码来源:LookupRef.php

示例2: extractNamedRange

 /**
  * Extract range values
  *
  * @param	string				&$pRange	String based range representation
  * @param	PHPExcel_Worksheet	$pSheet		Worksheet
  * @return  mixed				Array of values in range if range contains more than one element. Otherwise, a single value is returned.
  * @param	boolean				$resetLog	Flag indicating whether calculation log should be reset or not
  * @throws	PHPExcel_Calculation_Exception
  */
 public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = NULL, $resetLog = TRUE)
 {
     // Return value
     $returnValue = array();
     //		echo 'extractNamedRange('.$pRange.')<br />';
     if ($pSheet !== NULL) {
         $pSheetName = $pSheet->getTitle();
         //			echo 'Current sheet name is '.$pSheetName.'<br />';
         //			echo 'Range reference is '.$pRange.'<br />';
         if (strpos($pRange, '!') !== false) {
             //				echo '$pRange reference includes sheet reference',PHP_EOL;
             list($pSheetName, $pRange) = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
             //				echo 'New sheet name is '.$pSheetName,PHP_EOL;
             //				echo 'Adjusted Range reference is '.$pRange,PHP_EOL;
             $pSheet = $this->_workbook->getSheetByName($pSheetName);
         }
         // Named range?
         $namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet);
         if ($namedRange !== NULL) {
             $pSheet = $namedRange->getWorksheet();
             //				echo 'Named Range '.$pRange.' (';
             $pRange = $namedRange->getRange();
             $splitRange = PHPExcel_Cell::splitRange($pRange);
             //	Convert row and column references
             if (ctype_alpha($splitRange[0][0])) {
                 $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
             } elseif (ctype_digit($splitRange[0][0])) {
                 $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1];
             }
             //				echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />';
             //				if ($pSheet->getTitle() != $namedRange->getWorksheet()->getTitle()) {
             //					if (!$namedRange->getLocalOnly()) {
             //						$pSheet = $namedRange->getWorksheet();
             //					} else {
             //						return $returnValue;
             //					}
             //				}
         } else {
             return PHPExcel_Calculation_Functions::REF();
         }
         // Extract range
         $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
         //			var_dump($aReferences);
         if (!isset($aReferences[1])) {
             //	Single cell (or single column or row) in range
             list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]);
             $cellValue = NULL;
             if ($pSheet->cellExists($aReferences[0])) {
                 $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
             } else {
                 $returnValue[$currentRow][$currentCol] = NULL;
             }
         } else {
             // Extract cell data for all cells in the range
             foreach ($aReferences as $reference) {
                 // Extract range
                 list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($reference);
                 //					echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />';
                 $cellValue = NULL;
                 if ($pSheet->cellExists($reference)) {
                     $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
                 } else {
                     $returnValue[$currentRow][$currentCol] = NULL;
                 }
             }
         }
         //				print_r($returnValue);
         //			echo '<br />';
     }
     // Return
     return $returnValue;
 }
开发者ID:Princelo,项目名称:bioerp,代码行数:81,代码来源:Calculation.php

示例3: 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.
  * @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);
     // index_number must be greater than or equal to 1
     if ($index_number < 1) {
         return PHPExcel_Calculation_Functions::VALUE();
     }
     // index_number must be less than or equal to the number of columns in lookup_array
     if (!is_array($lookup_array) || empty($lookup_array)) {
         return PHPExcel_Calculation_Functions::REF();
     } else {
         $f = array_keys($lookup_array);
         $firstRow = array_pop($f);
         if (!is_array($lookup_array[$firstRow]) || $index_number > count($lookup_array[$firstRow])) {
             return PHPExcel_Calculation_Functions::REF();
         } else {
             $columnKeys = array_keys($lookup_array[$firstRow]);
             $firstkey = $f[0] - 1;
             $returnColumn = $firstkey + $index_number;
             $firstColumn = array_shift($f);
         }
     }
     if (!$not_exact_match) {
         $firstRowH = asort($lookup_array[$firstColumn]);
     }
     $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;
         }
         $rowNumber = $rowKey;
         $rowValue = $rowData;
     }
     if ($rowNumber !== false) {
         if (!$not_exact_match && $rowValue != $lookup_value) {
             //  if an exact match is required, we have what we need to return an appropriate response
             return PHPExcel_Calculation_Functions::NA();
         } else {
             //  otherwise return the appropriate value
             $result = $lookup_array[$returnColumn][$rowNumber];
             return $result;
         }
     }
     return PHPExcel_Calculation_Functions::NA();
 }
开发者ID:Brucewyh,项目名称:Questionnaire,代码行数:56,代码来源:LookupRef.php

示例4: testREF

 public function testREF()
 {
     $result = PHPExcel_Calculation_Functions::REF();
     $this->assertEquals('#REF!', $result);
 }
开发者ID:MyPHPTools,项目名称:PHPExcel,代码行数:5,代码来源:FunctionsTest.php

示例5: extractNamedRange

 /**
  * Extract range values
  *
  * @param	string				&$pRange	String based range representation
  * @param	PHPExcel_Worksheet	$pSheet		Worksheet
  * @return  mixed				Array of values in range if range contains more than one element. Otherwise, a single value is returned.
  * @throws	Exception
  */
 public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog = true)
 {
     // Return value
     $returnValue = array();
     //		echo 'extractNamedRange('.$pRange.')<br />';
     if (!is_null($pSheet)) {
         //			echo 'Current sheet name is '.$pSheet->getTitle().'<br />';
         //			echo 'Range reference is '.$pRange.'<br />';
         if (strpos($pRange, '!') !== false) {
             //				echo '$pRange reference includes sheet reference<br />';
             $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
             $pSheet = $pSheet->getParent()->getSheetByName($worksheetReference[0]);
             //				echo 'New sheet name is '.$pSheet->getTitle().'<br />';
             $pRange = $worksheetReference[1];
             //				echo 'Adjusted Range reference is '.$pRange.'<br />';
         }
         // Named range?
         $namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet);
         if (!is_null($namedRange)) {
             $pSheet = $namedRange->getWorksheet();
             ////			echo 'Named Range '.$pRange.' (';
             $pRange = $namedRange->getRange();
             ////				echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />';
             //				if ($pSheet->getTitle() != $namedRange->getWorksheet()->getTitle()) {
             //					if (!$namedRange->getLocalOnly()) {
             //						$pSheet = $namedRange->getWorksheet();
             //					} else {
             //						return $returnValue;
             //					}
             //				}
         } else {
             return PHPExcel_Calculation_Functions::REF();
         }
         // Extract range
         $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
         if (count($aReferences) == 1) {
             list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]);
             if ($pSheet->cellExists($aReferences[0])) {
                 $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
             } else {
                 $returnValue[$currentRow][$currentCol] = NULL;
             }
         } else {
             // Extract cell data
             foreach ($aReferences as $reference) {
                 // Extract range
                 list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($reference);
                 //					echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />';
                 if ($pSheet->cellExists($reference)) {
                     $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
                 } else {
                     $returnValue[$currentRow][$currentCol] = NULL;
                 }
             }
         }
         //				print_r($returnValue);
         //			echo '<br />';
     }
     // Return
     return $returnValue;
 }
开发者ID:fathitarek,项目名称:cop5725-dbms-project,代码行数:69,代码来源:Calculation.php

示例6: _processTokenStack


//.........这里部分代码省略.........
                     $stack->push($result);
                     break;
             }
             // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
         } elseif ($token === "_" || $token === "%") {
             //				echo 'Token is a unary operator<br />';
             if (is_null($arg = $stack->pop())) {
                 return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
             }
             if ($token === "_") {
                 //					echo 'Token is a negation operator<br />';
                 $this->_writeDebug($cellID, 'Evaluating Negation of ' . self::_showValue($arg));
                 $multiplier = -1;
             } else {
                 //					echo 'Token is a percentile operator<br />';
                 $this->_writeDebug($cellID, 'Evaluating Percentile of ' . self::_showValue($arg));
                 $multiplier = 0.01;
             }
             if (is_array($arg)) {
                 self::_checkMatrixOperands($arg, $multiplier);
                 try {
                     $matrix1 = new Matrix($arg);
                     $matrixResult = $matrix1->arrayTimesEquals($multiplier);
                     $result = $matrixResult->getArray();
                 } catch (Exception $ex) {
                     $this->_writeDebug($cellID, 'JAMA Matrix Exception: ' . $ex->getMessage());
                     $result = '#VALUE!';
                 }
             } else {
                 $result = $multiplier * $arg;
             }
             $this->_writeDebug($cellID, 'Evaluation Result is ' . self::_showTypeDetails($result));
             $stack->push($result);
         } elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $token, $matches)) {
             //				echo 'Element '.$token.' is a Cell reference<br />';
             if (isset($matches[8])) {
                 //					echo 'Reference is a Range of cells<br />';
                 if (is_null($pCell)) {
                     //						We can't access the range, so return a REF error
                     $cellValue = PHPExcel_Calculation_Functions::REF();
                 } else {
                     $cellRef = $matches[6] . $matches[7] . ':' . $matches[9] . $matches[10];
                     if ($matches[2] > '') {
                         //							echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
                         $this->_writeDebug($cellID, 'Evaluating Cell Range ' . $cellRef . ' in worksheet ' . $matches[2]);
                         $cellValue = $this->extractCellRange($cellRef, $pCell->getParent()->getParent()->getSheetByName($matches[2]), false);
                         $this->_writeDebug($cellID, 'Evaluation Result for cells ' . $cellRef . ' in worksheet ' . $matches[2] . ' is ' . self::_showTypeDetails($cellValue));
                     } else {
                         //							echo '$cellRef='.$cellRef.' in current worksheet<br />';
                         $this->_writeDebug($cellID, 'Evaluating Cell Range ' . $cellRef . ' in current worksheet');
                         $cellValue = $this->extractCellRange($cellRef, $pCell->getParent(), false);
                         $this->_writeDebug($cellID, 'Evaluation Result for cells ' . $cellRef . ' is ' . self::_showTypeDetails($cellValue));
                     }
                 }
             } else {
                 //					echo 'Reference is a single Cell<br />';
                 if (is_null($pCell)) {
                     //						We can't access the cell, so return a REF error
                     $cellValue = PHPExcel_Calculation_Functions::REF();
                 } else {
                     $cellRef = $matches[6] . $matches[7];
                     if ($matches[2] > '') {
                         //							echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
                         $this->_writeDebug($cellID, 'Evaluating Cell ' . $cellRef . ' in worksheet ' . $matches[2]);
                         if ($pCell->getParent()->cellExists($cellRef)) {
                             $cellValue = $this->extractCellRange($cellRef, $pCell->getParent()->getParent()->getSheetByName($matches[2]), false);
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:67,代码来源:Calculation.php

示例7: extractNamedRange

 /**
  * Extract range values
  *
  * @param	string				&$pRange	String based range representation
  * @param	PHPExcel_Worksheet	$pSheet		Worksheet
  * @return  mixed				Array of values in range if range contains more than one element. Otherwise, a single value is returned.
  * @param	boolean				$resetLog	Flag indicating whether calculation log should be reset or not
  * @throws	PHPExcel_Calculation_Exception
  */
 public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog = true)
 {
     // Return value
     $returnValue = array();
     if ($pSheet !== null) {
         $pSheetName = $pSheet->getTitle();
         if (strpos($pRange, '!') !== false) {
             list($pSheetName, $pRange) = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
             $pSheet = $this->_workbook->getSheetByName($pSheetName);
         }
         // Named range?
         $namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet);
         if ($namedRange !== null) {
             $pSheet = $namedRange->getWorksheet();
             $pRange = $namedRange->getRange();
             $splitRange = PHPExcel_Cell::splitRange($pRange);
             //	Convert row and column references
             if (ctype_alpha($splitRange[0][0])) {
                 $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
             } elseif (ctype_digit($splitRange[0][0])) {
                 $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1];
             }
         } else {
             return PHPExcel_Calculation_Functions::REF();
         }
         // Extract range
         $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
         if (!isset($aReferences[1])) {
             //	Single cell (or single column or row) in range
             list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]);
             $cellValue = null;
             if ($pSheet->cellExists($aReferences[0])) {
                 $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
             } else {
                 $returnValue[$currentRow][$currentCol] = null;
             }
         } else {
             // Extract cell data for all cells in the range
             foreach ($aReferences as $reference) {
                 // Extract range
                 list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($reference);
                 $cellValue = null;
                 if ($pSheet->cellExists($reference)) {
                     $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
                 } else {
                     $returnValue[$currentRow][$currentCol] = null;
                 }
             }
         }
     }
     // Return
     return $returnValue;
 }
开发者ID:ahmatjan,项目名称:OpenCart-Overclocked,代码行数:62,代码来源:Calculation.php


注:本文中的PHPExcel_Calculation_Functions::REF方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。