You are here

public function PHPExcel_Worksheet::duplicateConditionalStyle 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::duplicateConditionalStyle()

Duplicate conditional style to a range of cells

Please note that this will overwrite existing cell styles for cells in range!

*

Parameters

array of PHPExcel_Style_Conditional $pCellStyle Cell style to duplicate:

string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1"):

Return value

PHPExcel_Worksheet

Throws

PHPExcel_Exception

File

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

Class

PHPExcel_Worksheet
PHPExcel_Worksheet

Code

public function duplicateConditionalStyle(array $pCellStyle = null, $pRange = '') {
  foreach ($pCellStyle as $cellStyle) {
    if (!$cellStyle instanceof PHPExcel_Style_Conditional) {
      throw new PHPExcel_Exception('Style is not a conditional style');
    }
  }

  // Calculate range outer borders
  list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange . ':' . $pRange);

  // Make sure we can loop upwards on rows and columns
  if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
    $tmp = $rangeStart;
    $rangeStart = $rangeEnd;
    $rangeEnd = $tmp;
  }

  // Loop through cells and apply styles
  for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
    for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
      $this
        ->setConditionalStyles(PHPExcel_Cell::stringFromColumnIndex($col - 1) . $row, $pCellStyle);
    }
  }
  return $this;
}