PHPWord生成word实现table合并(colspan和rowspan)
2015-03-25 18:35
656 查看
PHPWord(http://phpword.codeplex.com/)是一个很好处理和生成WORD文档的工具,但是生成复杂的word,如colspan和rowspan的实现,还是需要你做些修改。
第一步:在phpword/Style/Cell.php文件类中添加如下属性:
第二步:在phpword/Style/Cell.php文件类中添加如下方法:
第三步:在phpword/Style/Cell.php文件类构造函数__construct()中添加如下:
第四步:在phpword/writer/word2007/base.php类的_writeCellStyle方法中添加:
OK,恭喜你,搞定了,然后看看怎么使用吧!
PHPWord rowspan的使用:
生成的word效果如下截图:
PHPWord colspan的使用:
生成word效果图如下:
第一步:在phpword/Style/Cell.php文件类中添加如下属性:
private $_gridSpan;// for the colspan private $_vMerge;// for the rowspan
第二步:在phpword/Style/Cell.php文件类中添加如下方法:
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; }
第三步:在phpword/Style/Cell.php文件类构造函数__construct()中添加如下:
$this->_gridSpan=null; $this->_vMerge=null;
第四步:在phpword/writer/word2007/base.php类的_writeCellStyle方法中添加:
$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,恭喜你,搞定了,然后看看怎么使用吧!
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');
生成的word效果如下截图:
PHPWord colspan的使用:
$table->addRow(); $styleCell=array('gridSpan' => 2); $table->addCell(200, $styleCell)->addText('PHP点点通'); $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);
生成word效果图如下:
相关文章推荐
- PHPWord生成word实现table合并(colspan和rowspan)
- 通过jquery还原含有rowspan、colspan的table的实现方法
- 【HTML】table表格拆分合并(colspan、rowspan)
- PHP生成word文档的三种实现方式
- PHP实现生成word文档
- 用PageOffice编程实现Word文件生成合并
- 使用Word的Mail Merge(邮件合并)功能实现批文档\邮件\通知的生成
- C# Html格式内容转Csv内容包括table(重点在rowspan和colspan合并),p,div元素
- 通过jquery还原含有rowspan、colspan的table的实现方法
- 用PageOffice编程实现Word文件生成合并
- php数组实现根据某个键值将相同键值合并生成新二维数组的方法
- html的table中rowspan colspan实现跨行或者跨列
- [原创] asp.net生成HTML的合并table行列rowspan的新方法
- PHP生成word文档的三种实现方式
- PHP实现生成GIF动态验证码图片功能
- php 生成word
- PHP安装加载yaf扩展,并用自动生成目录实现hello world程序
- 基于php实现随机合并数组并排序(原排序)
- PHP生成word的三种方式
- 一个php实现的生成排列的算法