2012-08-12 141 views

回答

5

添加这样的代码

1. PHPWord /组/表/ Cell.php

/** 
* How many columns this cell spans 
* @var int 
*/ 
private $_gridSpan; 

public function__construct($insideOf,$pCount,$width=null,$style=null,$gridSpan=1){ 
    $this->_insideOf = $insideOf; 
    ... 
    $this->_gridSpan = $gridSpan; 
} 

/** 
* Get the number of columns this cell spans 
* 
* @return int 
*/ 
public function getGridSpan(){ 
    return $this->_gridSpan; 
} 

2. PHPWord /组/ Table.php

 public function addCell($width,$style=null,$gridSpan=1){ 
      $cell = new PHPWord_Section_Table_Cell($this->_insideOf, 
        $this->_pCount,$width,$style,$gridSpan); 
     } 

3. PHPWord/Writer/Word2007/Base.php

protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table) { 
    $_rows = $table->getRows(); 
    $_cRows = count($_rows); 
    ... 
    $_heights = $table->getRowHeights(); 
    for ($i = 0; $i < $_cRows; $i++) { 
     $row = $_rows[$i]; 
     $height = $_heights[$i]; 
     //add 
     $objWriter->startElement('w:trPr'); 
     //FIXME: Make this an option on a row or table 
     $objWriter->startElement('w:cantSplit'); 
     $objWriter->endElement(); 
     $objWriter->endElement(); 
     //end add 
     foreach ($rows as $cell) { 
      ... 
      $width = $cell->getWidth(); 
      //add 
      $gridSpan = $cell->getGridSpan(); 
      //end add 
      ... 
      //add 
      if ($gridSpan > 1) { 
       $objWriter->startElement('w:gridSpan'); 
       $objWriter->writeAttribute('w:val',$gridSpan); 
       $objWriter->endElement(); 
       //end add 
       ... 
      } 
     } 
    } 
} 

您可以使用它像这样:

$PHPWord = new PHPWord(); 
$section = $PHPWord->createSection(); 
$table = $section->addTable(); 
$table->addRow(); 
$table->addCell(1000,null,2)->addText('info'); 

$table->addRow(); 
$table->addCell(500)->addText('Name'); 
$table->addCell(500)->addText('Sex'); 

很抱歉的风格,你可以使用它像这样:

$tableStyle = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80); 
$PHPWord->addTableStyle('tableStyle',$tableStyle,null); 
$table = $section->addTable('tableStyle'); 
$table->addRow(); 
$table->addCell(1000,null,2)->addText('info',null,array('align'=>'center')); 

$table->addRow(); 
$table->addCell(500)->addText('Name',null,array('align'=>'center')); 
$table->addCell(500)->addText('Sex',null,array('align'=>'center')); 
相关问题