我使用php word添加了两个徽标,但是两个徽标不在同一行:
我希望两个徽标位于同一行,如下所示:
我的错误在哪里?
if (file_exists($logo)) {
$table->addRow();
// $table->addCell(20000, array('bgColor' => 'ffffff', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0), $fontStyleIndexParaTitle)->addImage($logo, array('align' => 'center'));
$table->addCell(20000, array('bgColor' => 'ffffff', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0 ), $fontStyleIndexParaTitle)->addImage($logo, array('align' => 'left','width' => 70, 'height' => 70,));
}
if (file_exists($logo2)) {
$table->addRow();
// $table->addCell(20000, array('bgColor' => 'ffffff', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0), $fontStyleIndexParaTitle)->addImage($logo, array('align' => 'center'));
$table->addCell(20000, array('bgColor' => 'ffffff', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0 ), $fontStyleIndexParaTitle)->addImage($logo2, array('align' => 'right', 'width' => 130));
}
答案 0 :(得分:1)
如果存在一个或两个文件,则只想添加一行,因此请尝试以下操作:
if (file_exists($logo) || file_exists($logo2)) {
$table->addRow();
if (file_exists($logo)) {
$table->addCell(…);
}
if (file_exists($logo2)) {
$table->addCell(…);
}
}
编辑:此代码(使用phpoffice/phpword
v0.16.0):
<?php
require_once 'vendor/autoload.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$logo = 'logo.bmp';
$logo2 = 'logo2.bmp';
$section = $phpWord->addSection();
$table = $section->addTable();
if (file_exists($logo) || file_exists($logo2)) {
$table->addRow();
if (file_exists($logo)) {
$table->addCell(20000)->addImage($logo);
}
if (file_exists($logo2)) {
$table->addCell(20000)->addImage($logo2);
}
}
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('aman121.docx');
生成此Word文档(我的示例图像只是纯色矩形):