PHPWord (http://phpword.codeplex.com/) is a good tool to process and generate word documents, but to generate complex word, such as the implementation of colspan and rowspan, you still need to make some modifications.
PHPWord (http://phpword.codeplex.com/) is a good tool to process and generate word documents, but to generate complex word, such as the implementation of colspan and rowspan, you still need to make some modifications.
Step 1: Add the following attributes to the phpword/Style/Cell. php file class:
private $_gridSpan;// for the colspanprivate $_vMerge;// for the rowspan
Step 2: Add the following method to the phpword/Style/Cell. php file class:
public function setGridSpan($pValue = null) { $this->_gridSpan = $pValue; } public function getGridSpan() { return $this->_gridSpan; }public function setVMerge($pValue = null) { $this->_vMerge = $pValue; } public function getVMerge() { return $this->_vMerge; }
Step 3: Add the following in phpword/Style/Cell. php file class constructor _ construct:
$this->_gridSpan=null;$this->_vMerge=null;
Step 4: Add the following content to the _ writeCellStyle method of the phpword/writer/word2007/base. php class:
$gridSpan = $style->getGridSpan();if(!is_null($gridSpan)) { $objWriter->startElement('w:gridSpan'); $objWriter->writeAttribute('w:val', $gridSpan); $objWriter->endElement(); }/** edited by www.phpddt.com */$vMerge = $style->getVMerge(); if(!is_null($vMerge)) { $objWriter->startElement('w:vMerge'); $objWriter->writeAttribute('w:val', $vMerge); $objWriter->endElement(); }
OK. Congratulations, you have done it. then let's see how to use it!
Use of PHPWord rowspan:
$table = $section->addTable();$table->addRow();$table->addCell(100,array('vMerge' => 'restart'))->addText('1');$table->addCell(100)->addText('2');$table->addRow();$table->addCell(100,array('vMerge' => 'fusion'));$table->addCell(100)->addText('3');
The generated word is as follows:
Use of PHPWord colspan:
$ Table-> addRow (); $ styleCell = array ('gridspan '=> 2); $ table-> addCell (200, $ styleCell) -> addText ('php point pass'); $ table-> addCell (100)-> addText ('http: // www.phpddt.com '); $ table-> addRow (); $ table-> addCell (100)-> addText ('php'); $ table-> addCell (100)-> addText ('Python '); $ table-> addCell (100)-> addText ('Java'); $ section-> addTextBreak (10 );
The generated word is as follows:
Using PHPWord, I can easily generate complex words in projects. please leave a message if you have any questions!