PHPRtfLite_Table::getValidCellRange PHP Méthode

getValidCellRange() private static méthode

corrects cell range to be valid
private static getValidCellRange ( integer $startRow, integer $startColumn, integer $endRow, integer $endColumn ) : array
$startRow integer
$startColumn integer
$endRow integer
$endColumn integer
Résultat array
    private static function getValidCellRange($startRow, $startColumn, $endRow, $endColumn)
    {
        if ($endRow === null) {
            $endRow = $startRow;
        } elseif ($startRow > $endRow) {
            $temp = $startRow;
            $startRow = $endRow;
            $endRow = $temp;
        }
        if ($endColumn === null) {
            $endColumn = $startColumn;
        } elseif ($startColumn > $endColumn) {
            $temp = $startColumn;
            $startColumn = $endColumn;
            $endColumn = $temp;
        }
        return array($startRow, $startColumn, $endRow, $endColumn);
    }

Usage Example

Exemple #1
0
 /**
  * merges cells of a given cell range
  *
  * @param   integer $startRow       start row
  * @param   integer $startColumn    start column
  * @param   integer $endRow         end row
  * @param   integer $endColumn      end column
  *
  * @TODO add source code comments
  */
 public function mergeCellRange($startRow, $startColumn, $endRow, $endColumn)
 {
     list($startRow, $startColumn, $endRow, $endColumn) = PHPRtfLite_Table::getValidCellRange($startRow, $startColumn, $endRow, $endColumn);
     if ($startRow == $endRow && $startColumn == $endColumn) {
         return;
     }
     if (!$this->checkIfCellExists($endRow, $endColumn)) {
         return;
     }
     for ($j = $startRow; $j <= $endRow; $j++) {
         $start = $startColumn;
         $cell = $this->getCell($j, $start);
         while ($cell->isHorizontalMerged()) {
             $start--;
             $cell = $this->getCell($j, $start);
         }
         $end = $endColumn;
         $cell = $this->getCell($j, $end);
         while ($cell->isHorizontalMerged()) {
             $end++;
             $cell = $this->getCell($j, $end + 1);
         }
         $width = 0;
         for ($i = $start; $i <= $end; $i++) {
             $cell = $this->getCell($j, $i);
             if ($j == $startRow) {
                 $cell->setVerticalMergeStart();
             } else {
                 $cell->setVerticalMerged();
             }
             $width += $cell->getWidth();
             if ($i != $start) {
                 $cell->setHorizontalMerged();
             }
         }
         $this->getCell($j, $start)->setWidth($width);
     }
 }