You are here

public function PHPExcel_Worksheet::mergeCells in Loft Data Grids 7.2

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

Set merge on a cell range

Parameters

string $pRange Cell range (e.g. A1:E1):

Return value

PHPExcel_Worksheet

Throws

PHPExcel_Exception

1 call to PHPExcel_Worksheet::mergeCells()
PHPExcel_Worksheet::mergeCellsByColumnAndRow in vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet.php
Set merge on a cell range by using numeric cell coordinates

File

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

Class

PHPExcel_Worksheet
PHPExcel_Worksheet

Code

public function mergeCells($pRange = 'A1:A1') {

  // Uppercase coordinate
  $pRange = strtoupper($pRange);
  if (strpos($pRange, ':') !== false) {
    $this->_mergeCells[$pRange] = $pRange;

    // make sure cells are created
    // get the cells in the range
    $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);

    // create upper left cell if it does not already exist
    $upperLeft = $aReferences[0];
    if (!$this
      ->cellExists($upperLeft)) {
      $this
        ->getCell($upperLeft)
        ->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL);
    }

    // create or blank out the rest of the cells in the range
    $count = count($aReferences);
    for ($i = 1; $i < $count; $i++) {
      $this
        ->getCell($aReferences[$i])
        ->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL);
    }
  }
  else {
    throw new PHPExcel_Exception('Merge must be set on a range of cells.');
  }
  return $this;
}