You are here

public function PHPExcel_Worksheet::cellExists in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet.php \PHPExcel_Worksheet::cellExists()

Does the cell at a specific coordinate exist?

Parameters

string $pCoordinate Coordinate of the cell:

Return value

boolean

Throws

PHPExcel_Exception

2 calls to PHPExcel_Worksheet::cellExists()
PHPExcel_Worksheet::cellExistsByColumnAndRow in vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet.php
Cell at a specific coordinate by using numeric cell coordinates exists?
PHPExcel_Worksheet::mergeCells in vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet.php
Set merge on a cell range

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet.php, line 1256

Class

PHPExcel_Worksheet
PHPExcel_Worksheet

Code

public function cellExists($pCoordinate = 'A1') {

  // Worksheet reference?
  if (strpos($pCoordinate, '!') !== false) {
    $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true);
    return $this->_parent
      ->getSheetByName($worksheetReference[0])
      ->cellExists(strtoupper($worksheetReference[1]));
  }

  // Named range?
  if (!preg_match('/^' . PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $pCoordinate, $matches) && preg_match('/^' . PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE . '$/i', $pCoordinate, $matches)) {
    $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
    if ($namedRange !== NULL) {
      $pCoordinate = $namedRange
        ->getRange();
      if ($this
        ->getHashCode() != $namedRange
        ->getWorksheet()
        ->getHashCode()) {
        if (!$namedRange
          ->getLocalOnly()) {
          return $namedRange
            ->getWorksheet()
            ->cellExists($pCoordinate);
        }
        else {
          throw new PHPExcel_Exception('Named range ' . $namedRange
            ->getName() . ' is not accessible from within sheet ' . $this
            ->getTitle());
        }
      }
    }
    else {
      return false;
    }
  }

  // Uppercase coordinate
  $pCoordinate = strtoupper($pCoordinate);
  if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) {
    throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.');
  }
  elseif (strpos($pCoordinate, '$') !== false) {
    throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
  }
  else {

    // Coordinates
    $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);

    // Cell exists?
    return $this->_cellCollection
      ->isDataSet($pCoordinate);
  }
}