PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.27k stars 2.7k forks source link

The setComplexValue method has a bug when it saves the image of the docx document inserted by addImage #1685

Open xiao-kai opened 5 years ago

xiao-kai commented 5 years ago

Describe the Bug

my problem: After adding images to the docx document using the TextRun class instance addImage method, I used the setComplexValue method to replace the images to be added to the corresponding location of the docx document, and found that the inserted image element was a image showing nothing. 中文: 我使用TextRun类实例addImage方法向docx文档添加图片之后,再使用setComplexValue方法将所要添加的图片替换到docx文档相应的位置,结果发现插入的图片元素是一张啥都不显示的图片

Steps to Reproduce

Please provide a code sample that reproduces the issue.

<?php
$row=array();
$inline = new \PhpOffice\PhpWord\Element\TextRun;
$inline->addText(' ', array('italic' => true, 'color' => 'red'));
$sql = "select content,adduser,addtime from " . DB_PREFIX . "shouwen_yijian where tag = '2' and wen = '$id' order by adduser asc";
$rst = $mysql->execute($sql);
while ($row = $mysql->fetch($rst)) {
$inline->addText($row['content']);
$sign='D:\phpStudy\WWW\kjjoa\Manage_Cms\resource\signiture\'.$row['adduser'].'.jpg';
//echo $sign;die;
//$fileContent = file_get_contents($sign);
$inline->addImage($sign, array(
'marginTop' => 10,
'marginLeft' => 1,
'width' => 80,
));
}
//var_dump($inline);
$myfile->setComplexValue('{7}', $inline);

Expected Behavior

A clear and concise description of what you expected to happen.

Current Behavior

What is the current behavior?

Context

Please fill in your environment information:

netmou commented 5 years ago

Please forgive this Chinese boy with poor English. His main intention is to replace the mark in the template file with a image, but the image was not shown in result.

yidashi commented 4 years ago

the same to you