a suggestion to replace a token in template by a table
In /PHPWord/Shared/XMLWriter.php
Add this
replace on line 372 :
In /PHPWord/Shared/XMLWriter.php
Add this
public function setIndent($indent) {
$this->_xmlWriter->setIndent((bool)$indent);
}
public function setIndentString($indentString) {
$this->_xmlWriter->setIndentString((string)$indentString);
}
public function getWriter() {
return $this->_xmlWriter;
}
In /PHPWord/Writer/Word2007/Base.phpreplace on line 372 :
protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table)
by public function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table)And a example of use :$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('Template.docx');
// the construction of the table
$section = $PHPWord->createSection();
$table = $section->addTable();
$competences = array(
"Developpement" => array("JAVA","PHP","HTML", "ttttt"),
"Data base" => array("ORACLE","MYSQL","DATABASE", "ttttt"),
"Framework" => array("LIEFRY" ,"STRUTS" ,"NOHETO", "ttttt"),
);
foreach($competences as $cle1 => $valeur1)
{
foreach ($valeur1 as $cle2=>$valeur2)
{
$table->addRow();
$table->addCell(1750)->addText("$cle1,$valeur2");
}
}
$objWriter = new PHPWord_Shared_XMLWriter();
$objWriter->setIndent(FALSE);
$objWriter->setIndentString('');
$word2007Writer = new PHPWord_Writer_Word2007_Base();
$word2007Writer->_writeTable($objWriter, $table);
$xmlWriter = $objWriter->getWriter();
$output = $xmlWriter->outputMemory();
$document->setValue('test', $output );
$document->save('Solarsystem.docx');