Phpword (http://phpword.codeplex.com/) is a great tool for working with and generating word documents, but generating complex word, such as colspan and rowspan implementations, requires some modification.
Step 1: Add the following properties to the Phpword/style/cell.php file class:
Private $_gridspan;//for the colspan
Private $_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:In the phpword/style/cell.php file class constructor __construct (), add the following:
$this->_gridspan=null;
$this->_vmerge=null;
Step 4:Add in 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, it's done, then see how to use it!
use of Phpword rowspan:
$table = $section->addtable ();
$table->addrow ();
$table->addcell (100,array (' vmerge ' => ' restart '))->addtext (' 1 ');
$table->addcell (->addtext) (' 2 ');
$table->addrow ();
$table->addcell (100,array (' vmerge ' => ' fusion '));
$table->addcell (->addtext) (' 3 ');
The resulting word effects are screenshot of:
use of Phpword colspan:
$table->addrow ();
$styleCell =array (' Gridspan ' => 2);
$table->addcell ($styleCell)->addtext (' PHP two times development ');
$table->addcell (->addtext) (' http://www.111cn.net ');
$table->addrow ();
$table->addcell (->addtext) (' PHP ');
$table->addcell (->addtext) (' Python ');
$table->addcell (->addtext) (' Java ');
$section->addtextbreak (10);
Generate a word effect diagram as follows:
Psps6s.png "/>