You are here

public function PHPExcel_Calculation::extractCellRange in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php \PHPExcel_Calculation::extractCellRange()

* Extract range values * *

Parameters

string &$pRange String based range representation: * @param PHPExcel_Worksheet $pSheet Worksheet * @param boolean $resetLog Flag indicating whether calculation log should be reset or not * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned. * @throws PHPExcel_Calculation_Exception

1 call to PHPExcel_Calculation::extractCellRange()
PHPExcel_Calculation::_processTokenStack in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php, line 3748

Class

PHPExcel_Calculation
PHPExcel_Calculation (Multiton)

Code

public function extractCellRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = NULL, $resetLog = TRUE) {

  // Return value
  $returnValue = array();

  //		echo 'extractCellRange('.$pRange.')',PHP_EOL;
  if ($pSheet !== NULL) {
    $pSheetName = $pSheet
      ->getTitle();

    //			echo 'Passed sheet name is '.$pSheetName.PHP_EOL;
    //			echo 'Range reference is '.$pRange.PHP_EOL;
    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);
    }

    // Extract range
    $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
    $pRange = $pSheetName . '!' . $pRange;
    if (!isset($aReferences[1])) {

      //	Single cell in range
      sscanf($aReferences[0], '%[A-Z]%d', $currentCol, $currentRow);
      $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
        sscanf($reference, '%[A-Z]%d', $currentCol, $currentRow);
        $cellValue = NULL;
        if ($pSheet
          ->cellExists($reference)) {
          $returnValue[$currentRow][$currentCol] = $pSheet
            ->getCell($reference)
            ->getCalculatedValue($resetLog);
        }
        else {
          $returnValue[$currentRow][$currentCol] = NULL;
        }
      }
    }
  }

  // Return
  return $returnValue;
}