lib/PHPRtfLite/Table.php
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);
        }
    }
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);
        }
    }
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 ) ; } }
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
merges cells of a given cell range