<?php
/**
* PHPWord
*
* Copyright (c) 2011 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 010 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version Beta 0.6.3, 08.07.2011
*/
class PHPWord_Writer_Word2007_Base extends PHPWord_Writer_Word2007_WriterPart {
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
}
}
}
protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun) {
$elements = $textrun->getElements();
$styleParagraph = $textrun->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
$objWriter->startElement('w:p');
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();
}
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element, true);
} elseif ($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element, true);
}
}
}
$objWriter->endElement();
}
protected function _writeParagraphStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_Paragraph $style, $withoutPPR = false) {
$align = $style->getAlign();
$spaceBefore = $style->getSpaceBefore();
$spaceAfter = $style->getSpaceAfter();
$spacing = $style->getSpacing();
if (!is_null($align) || !is_null($spacing) || !is_null($spaceBefore) || !is_null($spaceAfter)) {
if (!$withoutPPR) {
$objWriter->startElement('w:pPr');
}
if (!is_null($align)) {
$objWriter->startElement('w:jc');
$objWriter->writeAttribute('w:val', $align);
$objWriter->endElement();
}
if (!is_null($spaceBefore) || !is_null($spaceAfter) || !is_null($spacing)) {
$objWriter->startElement('w:spacing');
if (!is_null($spaceBefore)) {
$objWriter->writeAttribute('w:before', $spaceBefore);
}
if (!is_null($spaceAfter)) {
$objWriter->writeAttribute('w:after', $spaceAfter);
}
if (!is_null($spacing)) {
$objWriter->writeAttribute('w:line', $spacing);
$objWriter->writeAttribute('w:lineRule', 'auto');
}
$objWriter->endElement();
}
if (!$withoutPPR) {
$objWriter->endElement(); // w:pPr
}
}
}
protected function _writeLink(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Link $link, $withoutP = false) {
$rID = $link->getRelationId();
$linkName = $link->getLinkName();
if (is_null($linkName)) {
$linkName = $link->getLinkSrc();
}
$styleFont = $link->getFontStyle();
$SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
if (!$withoutP) {
$objWriter->startElement('w:p');
$styleParagraph = $link->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();
}
}
$objWriter->startElement('w:hyperlink');
$objWriter->writeAttribute('r:id', 'rId' . $rID);
$objWriter->writeAttribute('w:history', '1');
$objWriter->startElement('w:r');
if ($SfIsObject) {
$this->_writeTextStyle($objWriter, $styleFont);
} elseif (!$SfIsObject && !is_null($styleFont)) {
$objWriter->startElement('w:rPr');
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PHPWord.rar (60个子文件)
PHPWord
PHPWord
Media.php 8KB
TOC.php 3KB
DocumentProperties.php 5KB
Writer
IWriter.php 1KB
Word2007.php 9KB
Word2007
DocumentRels.php 5KB
Styles.php 12KB
Header.php 3KB
ContentTypes.php 6KB
Rels.php 3KB
WriterPart.php 1KB
Base.php 28KB
Document.php 16KB
DocProps.php 6KB
Footer.php 3KB
_staticDocParts
fontTable.xml 2KB
webSettings.xml 259B
settings.xml 2KB
_ppt.png 2KB
_doc.png 1KB
theme1.xml 7KB
_xls.png 2KB
numbering.xml 27KB
IOFactory.php 3KB
Style.php 4KB
Shared
XMLWriter.php 4KB
Drawing.php 2KB
File.php 3KB
ZipStreamWrapper.php 4KB
String.php 7KB
Font.php 2KB
Autoloader.php 2KB
Section
Footer
PreserveText.php 3KB
PageBreak.php 1KB
Header.php 5KB
ListItem.php 2KB
Settings.php 9KB
Image.php 3KB
Table
Cell.php 8KB
TextRun.php 3KB
Object.php 3KB
Text.php 3KB
Table.php 3KB
Link.php 3KB
TextBreak.php 1KB
Title.php 2KB
Footer.php 5KB
MemoryImage.php 4KB
Template.php 3KB
Style
TOC.php 3KB
ListItem.php 2KB
Image.php 3KB
Cell.php 7KB
TableFull.php 9KB
Table.php 2KB
Font.php 6KB
Paragraph.php 3KB
Section.php 8KB
PHPWord.php 5KB
demo.php 4KB
共 60 条
- 1
资源评论
紫云沫雪こ
- 粉丝: 45
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- mmexport1713192608513.mp4
- 斯特林V4发动机 斯特林V4发动机
- 基于C实现的N阶数字正方形 ;N阶数字三角形;N阶数字递减三角形;乘法表
- 基于分水岭算法的图像分割的python源码(课程设计).zip
- 基于Java 实现的二进制十进制之间的相互转换
- Pytorch实现基于卷积神经网络的面部表情识别项目源码+数据集+全部资料(毕业设计).zip
- Pytorch实现基于深度学习卷积神经网络的面部表情识别项目源码+面部表情数据集(人脸面部表情识别项目).zip
- 淘金小游戏助手.apk
- 基于卷积神经网络的人脸面部表情识别项目源码+面部表情数据集+训练好的模型(人脸面部表情识别项目).zip
- 深度学习基于卷积神经网络的人脸面部表情识别项目源码+面部表情数据集+训练好的模型(人脸面部表情识别项目).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功