在php word中将两个徽标对齐在同一行中
我使用php word添加了两个徽标,但两个徽标不在同一行: 我希望两个徽标位于同一行,如下所示: 我的错在哪里在php word中将两个徽标对齐在同一行中,php,phpword,Php,Phpword,我使用php word添加了两个徽标,但两个徽标不在同一行: 我希望两个徽标位于同一行,如下所示: 我的错在哪里 if (file_exists($logo)) { $table->addRow(); // $table->addCell(20000, array('bgColor' => 'ffffff', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0), $fontStyle
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));
}
如果其中一个或两个文件都存在,则只需添加一行,请尝试以下操作:
if (file_exists($logo) || file_exists($logo2)) {
$table->addRow();
if (file_exists($logo)) {
$table->addCell(…);
}
if (file_exists($logo2)) {
$table->addCell(…);
}
}
编辑:此代码(使用phpooffice/phpword
v0.16.0):
Hi@sean感谢您的回复,但当我添加这些代码时,这些代码徽标将从我的文件中完全删除感谢您的努力,兄弟,但是这对我没有帮助,我实现了你的代码,并且在我设置高度和宽度之前,图像遍布了整个页面。我现在使用这段代码,但它没有给我一个间隙选项。图像太接近你的$logo='pearson1.png'$logo2='genesis2.png'$section=$phpWord->addSection()$table=$section->addTable();如果(文件存在($logo)|文件存在($logo2)){$table->addRow();如果(文件存在($logo)){$table->addCell(20000)->addImage($logo,array('width'=>70','height'=>70');}如果(文件存在($logo2)){$table->addCell(20000)->addImage($logo,array('width'=>120','height'=>40'));}
是的,但如果您能给我间隙或对齐的解决方案,我将不胜感激,因为我尝试了所有方法,但没有任何效果
<?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');