[英]Align two logos in same line in php word
我使用 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));
}
如果存在一個或兩個文件,您只想添加一行,請嘗試以下操作:
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 文檔(我的示例圖像只是純色矩形):
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.