Author: Denis Slaveckij (info@phprtf.com)
Author: Steffen Zeidler (sigma_z@web.de)
Exemple #1
0
 /**
  * sets default font for all cells in the row
  *
  * @param PHPRtfLite_Font $font
  */
 public function setFont(PHPRtfLite_Font $font)
 {
     $rows = $this->_table->getRows();
     foreach ($rows as $row) {
         $cell = $this->_table->getCell($row->getRowIndex(), $this->_columnIndex);
         $cell->setFont($font);
     }
 }
Exemple #2
0
 /**
  * tests setBorder on cell 2x2
  * @depends testSetBorderForCellWithRow2Column1
  *
  * @param  PHPRtfLite_Table $table
  */
 public function testSetBorderForCellWithRow2Column2(PHPRtfLite_Table $table)
 {
     $border = new PHPRtfLite_Border($table->getRtf());
     $border->setBorders(new PHPRtfLite_Border_Format(1, '#888'));
     $cell2x2 = $table->getCell(2, 2);
     $cell1x2 = $table->getCell(1, 2);
     $cell2x1 = $table->getCell(2, 1);
     $cell2x2->setBorder($border);
     $this->assertEquals('#3F3', $cell1x2->getBorder()->getBorderTop()->getColor());
     $this->assertEquals('#888', $cell1x2->getBorder()->getBorderBottom()->getColor());
     $this->assertEquals('#888', $cell2x1->getBorder()->getBorderRight()->getColor());
 }
Exemple #3
0
 /**
  * renders rtf code for cell
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     $stream->write("\r\n");
     // renders container elements
     parent::render();
     $containerElements = $this->getElements();
     $numOfContainerElements = count($containerElements);
     if ($this->_table->isNestedTable()) {
         // if last container element is not a nested table, close cell
         if ($numOfContainerElements == 0 || !$containerElements[$numOfContainerElements - 1] instanceof PHPRtfLite_Table_Nested) {
             $stream->write('{\\nestcell{\\nonesttables\\par}\\pard}' . "\r\n");
             // if last cell of row, close row
             if ($this->getColumnIndex() == $this->_table->getColumnsCount()) {
                 $stream->write('{\\*\\nesttableprops ');
                 $row = $this->_table->getRow($this->_rowIndex);
                 $this->_table->renderRowDefinition($row);
                 $stream->write('\\nestrow}');
             }
         }
     } else {
         if ($numOfContainerElements > 0 && $containerElements[$numOfContainerElements - 1] instanceof PHPRtfLite_Table_Nested) {
             $stream->write('\\intbl\\itap1\\~');
         }
         // closing tag for cell definition
         $stream->write('\\cell');
     }
     $stream->write("\r\n");
 }
Exemple #4
0
 /**
  * sets default font for all cells in the row
  *
  * @param PHPRtfLite_Font $font
  */
 public function setFont(PHPRtfLite_Font $font)
 {
     $columns = $this->_table->getColumns();
     foreach ($columns as $i => $column) {
         $cell = $this->_table->getCell($this->_rowIndex, $column->getColumnIndex());
         $cell->setFont($font);
     }
 }
Exemple #5
0
 /**
  * Gets rtf code for cell
  *
  * @return string rtf code
  */
 public function getContent()
 {
     $content = '{';
     switch ($this->_alignment) {
         case self::TEXT_ALIGN_LEFT:
             $content .= '\\ql';
             break;
         case self::TEXT_ALIGN_CENTER:
             $content .= '\\qc';
             break;
         case self::TEXT_ALIGN_RIGHT:
             $content .= '\\qr';
             break;
         case self::TEXT_ALIGN_JUSTIFY:
             $content .= '\\qj';
             break;
     }
     if ($this->_font) {
         $content .= $this->_font->getContent($this->_table->getRtf());
     }
     $content .= parent::getContent() . '\\cell \\pard }' . "\r\n";
     return $content;
 }
Exemple #6
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);
     }
 }
Exemple #7
0
 /**
  * tests checkIfCellExists
  * @depends testCheckIfCellExistsStartIndex
  */
 public function testCheckIfCellExistsOutOfIndex(PHPRtfLite_Table $table)
 {
     $this->assertFalse($table->checkIfCellExists(4, 4));
 }
Exemple #8
0
 /**
  * tests getCellByIndex
  * @return void
  */
 public function testGetCellByIndex()
 {
     $this->_table->addRow(5);
     $row = $this->_table->getRow(1);
     $this->assertType('PHPRtfLite_Table_Cell', $row->getCellByIndex(5));
 }