PHPWord 表格居中和合并单元格

/PHPWord/Style/Cell.php添加属性和方法

    private $_rowMerge = null;  
    private $_cellMerge = null;  

    public function getRowMerge()  
    {  
        return $this->_rowMerge;  
    }  

    public function setRowMerge($pValue = null)  
    {  
        $this->_rowMerge = $pValue;  
        return $this;  
    }  

    public function getCellMerge()  
    {  
        return $this->_cellMerge;  
    }  

    public function setCellValue($pValue = null)  
    {  
        $this->_cellMerge = $pValue;  
        return $this;  
    }  

/PHPWord/Writer/Word2007/base.php中_writeCellStyle方法添加

    $rowMerge = $style->getRowMerge();    
    $cellMerge = $style->getCellMerge();  

在同方法中修改 styles()if( styles)代码块里面:

    $styles = (!is_null($bgColor) || !is_null($valign) || !is_null($textDir)   
     || $borders || !is_null($rowMerge) || !is_null($cellMerge)) ? true : false;  

在同方法if ($styles)中添加

    if (!is_null($cellMerge))  
    {  
        //$objWriter->startElement('w:gridSpan');  
        $objWriter->startElement('w:hMerge');  
        if ((string)$cellMerge !== 'continue')  
        {   
                                 $objWriter->writeAttribute('w:val', $cellMerge);  
        }  
                             $objWriter->endElement();  
    }  

    if (!is_null($rowMerge))  
    {  
        $objWriter->startElement('w:vMerge');  
        if ((string)$rowMerge !== 'continue')  
        {  
                                 $objWriter->writeAttribute('w:val', $rowMerge);  
        }  
                             $objWriter->endElement();  
    }  

使用方法:

$styleTable = array('borderSize'=>6, 'borderColor'=>'000000', 'cellMargin'=>80);  
$styleCell = array('valign'=>'center', 'align'=>'center');  
$fontStyle = array('size'=>10 /*,'bold'=>true*/);  
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $fontStyle);  
$table = $section->addTable('myOwnTableStyle');  
$table->addRow();  
$table->addCell(1600)->addText('分类', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('序号', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('制作项目', $fontStyle, $styleCell);  
$table->addCell(2000)->addText('制作说明', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('采用技术', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('报价', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('数量', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('总价', $fontStyle, $styleCell);  
$table->addCell(2600)->addText('备注', $fontStyle, $styleCell);  

$table->addRow();  
$table->addCell(600, array('rowMerge' => 'restart', 'valign' => "center"))->addText('内容部分');  
$table->addCell(1600)->addText('1', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('片头LOGO演绎', $fontStyle, $styleCell);  
$table->addCell(2000)->addText('10秒左右的视频制作', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('AE', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('2000元/个', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('1', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('', $fontStyle, $styleCell);  
$table->addCell(2600)->addText('', $fontStyle, $styleCell);  

$table->addRow();  
$table->addCell(1600, array('rowMerge' => 'continue'));  
$table->addCell(1600)->addText('2', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('UI界面设计', $fontStyle, $styleCell);  
$table->addCell(2000)->addText('程序框架设计及动态交互设计', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('AI/PS', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('7000元/套', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('1', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('', $fontStyle, $styleCell);  
$table->addCell(2600)->addText('', $fontStyle, $styleCell);  

$table->addRow();  
$table->addCell(1600, array('rowMerge' => 'continue'));  
$table->addCell(1600)->addText('3', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('文案创意撰写', $fontStyle, $styleCell);  
$table->addCell(2000)->addText('系统中要表现的项目内容的创意和文案撰写', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('文案策划创意', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('6000元/套', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('1', $fontStyle, $styleCell);  
$table->addCell(1600)->addText('', $fontStyle, $styleCell);  
$table->addCell(2600)->addText('建议不做', $fontStyle, $styleCell);  


$table->addRow(400);    
$table->addCell(1600, array('cellMerge' => 'restart', 'valign' => "center"))->addText('横向合并');    
$table->addCell(1600, array('cellMerge' => 'continue'));    
$table->addCell(1600, array('cellMerge' => 'continue'));    
$table->addCell(1600, array('cellMerge' => 'continue')); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值