$phpWord = new \PhpOffice\PhpWord\PhpWord();
function table() {
$section = $phpWord->addSection();
$table = $section->addTable();
for ($r = 1; $r <= 8; $r++) {
$table->addRow();
for ($c = 1; $c <= 5; $c++) {
$table->addCell(1750)->addText("Row {$r}, Cell {$c}");
}
}
}
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor("table.docx");
$templateProcessor->setValue('table', table());
$templateProcessor->saveAs("1111.docx");
$obPHPWord = new PHPWord();
$obPHPWordDocument = $obPHPWord->loadTemplate('template.docx');
$section = $this->obPHPWord->createSection();
$table = $section->addTable();
$table->addRow(900);
// Add cells
$table->addCell(2000)->addText('Col 1');
$table->addCell(2000)->addText('Col 2');
$table->addCell(2000)->addText('Col 3');
$objWriter = PHPWord_IOFactory::createWriter($obPHPWord, 'Word2007');
$sTableText = $objWriter->getWriterPart('document')->getObjectAsText($table);
$obPHPWordDocument->setValue('myTable', $sTableText);
$obPHPWordDocument->save('result.docx');
$templateProcessor->setValue('table', table());
$templateProcessor->setComplexBlock('table', $table);
$templateProcessor = new PhpOffice\PhpWord\TemplateProcessor($templateFile);
$table = new \PhpOffice\PhpWord\Element\Table(array('borderSize' => 6, 'borderColor' => 'black', 'unit' => 'pct', 'width' => 100 * 50));
$table->addRow();
$table->addCell(1000)->addText('Колонка 1');
$table->addCell(2000)->addText('Колонка 2');
$table->addCell(1000)->addText('Колонка 3');
$templateProcessor->setComplexBlock('TABLE', $table);