我正在尝试使用laravel创建Word文件,但我成功创建了文件,但是我只停留在将图像添加到Word文档中的一件事上。文本已加载到Word文件中是正确的,但未加载图像。 听到我附上我的代码和html预览图像
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$i=1;
foreach ($que['que'] as $key => $value) {
if($value['qtype'] == 'text'){
$text = $section->addText("Q".$i." : ".$value['questions'],array('name'=>'Arial','size' => 12,'bold' => true));}
else
{
$source='http://localhost:81/paper_genrator/storage/app/public/images/'.$value['questions'];
$text = $section->addImage($source);
}
$text = $section->addText(" ");
$text = $section->addText("A : ".$value['option1']);
$text = $section->addText("B : ".$value['option2']);
$text = $section->addText("C : ".$value['option3']);
$text = $section->addText("D : ".$value['option4']);
$text = $section->addText(" ");
$i++;
}
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($que['que'][0]['cp_name'].'.docx');