PHPRtfLite_Table::setTextAlignmentForCellRange PHP Method

setTextAlignmentForCellRange() public method

sets alignments to empty cells of a given cell range
public setTextAlignmentForCellRange ( string $alignment, integer $startRow, integer $startColumn, integer $endRow = null, integer $endColumn = null )
$alignment string alignment of cell. The method PHPRtfLite_Table_Cell->writeToCell() overrides it with PHPRtfLite_ParFormat alignment.
Alignment is represented by class constants PHPRtfLite_Container::TEXT_ALIGN_*
Possible values:
PHPRtfLite_Container::TEXT_ALIGN_LEFT => 'left' - left alignment
PHPRtfLite_Container::TEXT_ALIGN_RIGHT => 'right' - right alignment
PHPRtfLite_Container::TEXT_ALIGN_CENTER => 'center' - center alignment
PHPRtfLite_Container::TEXT_ALIGN_JUSTIFY => 'justify' - justify alignment
$startRow integer start row
$startColumn integer start column
$endRow integer end row, if null, then text alignment is set only to the row range.
$endColumn integer end column, if null, then text alignment is set just to the column range.
    public function setTextAlignmentForCellRange($alignment, $startRow, $startColumn, $endRow = null, $endColumn = null)
    {
        list($startRow, $startColumn, $endRow, $endColumn) = PHPRtfLite_Table::getValidCellRange($startRow, $startColumn, $endRow, $endColumn);
        if ($this->checkIfCellExists($startRow, $startColumn) && $this->checkIfCellExists($endRow, $endColumn)) {
            $cells = $this->getCellsByCellRange($startRow, $startColumn, $endRow, $endColumn);
            foreach ($cells as $cell) {
                $cell->setTextAlignment($alignment);
            }
        }
    }

Usage Example

Example #1
0
 /**
  * tests setTextAlignmentForCellRange
  */
 public function testSetTextAlignmentForCell()
 {
     $this->_table->addRows(3);
     $this->_table->addColumnsList(array(5, 5, 5));
     $this->_table->setTextAlignmentForCellRange(PHPRtfLite_Table_Cell::TEXT_ALIGN_CENTER, 2, 2);
     $cell = $this->_table->getCell(2, 2);
     $this->assertEquals(PHPRtfLite_Table_Cell::TEXT_ALIGN_CENTER, $cell->getTextAlignment());
 }