PHPword 表格内换行处理
来源:互联网 发布:矩阵型组织结构 编辑:程序博客网 时间:2024/05/21 06:44
PHPWord文本换行很简单:
$PHPWord = new PHPWord();$section = $PHPWord->createSection();$section->addText('php点点通-www.phpddt.com');$section->addTextBreak(1);//换行
但是在添加table的cell单元格中换行,好像没有相应的方法,提供一个PHPWord实现table cell单元格内容换行解决方案如下:
把phpword/writer/word2007/base.php中_writeText()方法替换如下:
protected function _writeText(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Text $text, $withoutP = false) { $styleFont = $text->getFontStyle(); $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false; //@blog<www.phpddt.com> $strText = htmlspecialchars($text->getText()); // 将文本用/n分割成数组 $str_tmp=explode("/n",$strText); // 循环输出数组文本 for ($i = 0; $i < count($str_tmp); $i++) { if(!$withoutP) { $objWriter->startElement('w:p'); $styleParagraph = $text->getParagraphStyle(); $SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false; if($SpIsObject) { $this->_writeParagraphStyle($objWriter, $styleParagraph); } elseif(!$SpIsObject && !is_null($styleParagraph)) { $objWriter->startElement('w:pPr'); $objWriter->startElement('w:pStyle'); $objWriter->writeAttribute('w:val', $styleParagraph); $objWriter->endElement(); $objWriter->endElement(); } } $strText = htmlspecialchars($text->getText()); $strText = PHPWord_Shared_String::ControlCharacterPHP2OOXML($strText); $strText = $str_tmp[$i]; $strText = PHPWord_Shared_String::ControlCharacterPHP2OOXML($strText); $objWriter->startElement('w:r'); if($SfIsObject) { $this->_writeTextStyle($objWriter, $styleFont); } elseif(!$SfIsObject && !is_null($styleFont)) { $objWriter->startElement('w:rPr'); $objWriter->startElement('w:rStyle'); $objWriter->writeAttribute('w:val', $styleFont); $objWriter->endElement(); $objWriter->endElement(); } $objWriter->startElement('w:t'); $objWriter->writeAttribute('xml:space', 'preserve'); // needed because of drawing spaces before and after text $objWriter->writeRaw($strText); $objWriter->endElement(); $objWriter->endElement(); // w:r if(!$withoutP) { $objWriter->endElement(); // w:p } } }
只要在表格内容里面 加上 /n就可以换行了!
0 0
- PHPword 表格内换行处理
- 表格自动换行处理
- Latex 表格单元格内换行
- latex表格单元格内换行
- 表格内文字不换行
- Markdown表格之表格内换行
- 网页表格内单元格内自动换行
- 表格处理:换行还是不换行?
- 表格内td的内容自动换行
- Latex 表格内文字过长自动换行
- poi导出word 表格 单元格内换行
- Latex 表格内文字过长自动换行
- 表格内的文字不会自动换行
- markdown表格内如何进行换行?
- LaTex表格内单元格内容强制换行
- LaTex表格内单元格内容强制换行
- PhpWord 如何输出换行符到 word?
- PHPWord
- ffmpeg基础知识
- 用python-pulp解决线性规划问题
- web.xml配置,避免乱码
- 解决:Xvfb 缺少cyrillic 100dpi 75dpi 100dpi 75dpi
- LeedCode 之 Plus One
- PHPword 表格内换行处理
- STL:set详解
- Joint Face Detection and Alignment Using Multi-task Cascade Convolutional Networks笔记
- mybatis generator xml配置模板
- [Leetcode] #343 Integer Break (DP)
- RateLimit--使用guava来做接口限流
- 虚拟机装win7
- Utgard使用总结(OPC)
- 进程三态