标签 phpoffice 下的文章

去除phpoffice默认插入图片产生边框

项目中通过phpoffice(v0.17)生成word文件,插入word的图片默认带黑边框问题。

解决方式:
路径:vendor/phpoffice/phpword/src/PhpWord/TemplateProcess.php

位置:578行 stroked=""
$imgTpl = '<w:pict><v:shape type="#_x0000_t75" style="width:{WIDTH};height:{HEIGHT};" stroked=""><v:imagedata r:id="{RID}" o:title=""/></v:shape></w:pict>';

phpword添加批注注释信息

$phpWord = \PhpOffice\PhpWord\IOFactory::load("/test/test1.docx");

//创建注释
$comment= new \PhpOffice\PhpWord\Element\Comment('森森', new \DateTime(), 'my_initials');
$comment->addText('这是批注的信息内容', array('bold' => false, 'color'=>'ff0000'));

//添加到注释
$phpWord->addComment($comment);

$section = $phpWord->getSection(0);

//创建文本并添加注释
$textrun = $section->addTextRun();
$textrun->addText('这里需要进行');
$text = $textrun->addText('注释');
//将注释链接到刚创建的文本上
$text->setCommentRangeStart($comment);
//也可以为注释设置起始位置
//$comment->setStartElement($text);

//原始文本添加注释

//导出注释版
$phpWord->save("/test/test2.docx");

1111.png