/** * Add/get row */ public function testRow() { $oTable = new Table(); $element = $oTable->addRow(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element); $this->assertCount(1, $oTable->getRows()); }
/** * Write column. * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param \PhpOffice\PhpWord\Element\Table $element * @return void */ private function writeColumns(XMLWriter $xmlWriter, TableElement $element) { $rows = $element->getRows(); $rowCount = count($rows); $cellWidths = array(); for ($i = 0; $i < $rowCount; $i++) { $row = $rows[$i]; $cells = $row->getCells(); if (count($cells) <= count($cellWidths)) { continue; } $cellWidths = array(); foreach ($cells as $cell) { $cellWidths[] = $cell->getWidth(); } } $xmlWriter->startElement('w:tblGrid'); foreach ($cellWidths as $width) { $xmlWriter->startElement('w:gridCol'); if ($width !== null) { $xmlWriter->writeAttribute('w:w', $width); $xmlWriter->writeAttribute('w:type', 'dxa'); } $xmlWriter->endElement(); } $xmlWriter->endElement(); // w:tblGrid }
private function parseTable(Table $table, iCallback $callback) { foreach ($table->getRows() as $row) { foreach ($row->getCells() as $cell) { $this->parseContainer($cell, $callback); } } }