【问题标题】:Neither image gap nor image alignment is working in phpword图像间隙和图像对齐都不适用于phpword
【发布时间】:2019-07-11 12:34:50
【问题描述】:

我在同一行中有两张图片,我想在它们之间放置一些空间。

即使我努力寻找解决方案,目前也没有任何效果。

代码如下:

$section = $phpWord->addSection($PidPageSettings);
$table = $section->addTable();

$logo = 'pearson1' . $clientid . ".png";
$logo2 = 'genesis2' . $clientid . ".png";

// $table = $section->addTable();
// $table->addRow();
// $cell = $table->addCell(20000, array('bgColor' => 'ffffff'));

$table = $section->addTable();
$table->addRow();
$table->addCell(2000, $cellRowSpan)->addImage('pearson1.png',array('width' => '70','height' => '70','valign' => 'left'));
$table->addCell(2000, $cellRowSpan)->addImage('genesis2.png',array('width' => '120','height' => '40')); 

【问题讨论】:

    标签: php phpword


    【解决方案1】:

    使用图片margin调整两张图片之间的间距

    marginLeft。左边距以英寸为单位,可以为负数。

    边距顶部。以英寸为单位的上边距,可以为负数。

    在示例中为 20,根据您的需要进行调整。

    注意垂直对齐

    对齐。垂直对齐,顶部,中心,两者,底部。

    所以 leftvalign 无效。此外,它是针对细胞的,而不是针对图像的。 valign 设置应包含在您的 $cellRowSpan 中,例如: $cellRowSpan = array('valign' => 'center');

    设置图像对齐方式,例如:\PhpOffice\PhpWord\SimpleType\Jc::CENTER,如 this example

    如果您想调整图像尺寸,请调整宽度和高度。

    高度。高度(磅)。

    宽度。以pt为单位的宽度。

    例如(根据需要调整参数):

    $table->addCell(2000, $cellRowSpan)->addImage('pearson1.png',array('width' => 70,'height' => 70, 'marginLeft' => 20, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
    $table->addCell(2000, $cellRowSpan)->addImage('genesis2.png',array('width' => 210,'height' => 70, 'marginLeft' => 20, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER)); 
    

    【讨论】:

    • 谢谢哥们,但它给出了一个错误 - 未捕获的错误:在 C:\xampp\htdocs\report edite\vendor\phpoffice\phpword\src\ 中调用一个成员函数 addCell() on null PhpWord\Element\Table.php:85 堆栈跟踪:#0 C:\xampp\htdocs\report edite\sreport_new_I0027.php(305): PhpOffice\PhpWord\Element\Table->addCell(2000, NULL) #1 {main } 在第 85 行的 C:\xampp\htdocs\report edite\vendor\phpoffice\phpword\src\PhpWord\Element\Table.php 中抛出
    • 您的新代码现在没有出错,但也无助于对齐或减少差距。 :(
    • 谢谢你的帮助,我真的很感激兄弟,我想知道你有没有实际尝试过,因为这根本不适合我:/我想我这边可能有一些问题无法追踪。
    • 变量$cellRowSpan中有什么?
    • 在这里你可以找到我在使用这个库时读过的例子github.com/PHPOffice/PHPWord/tree/master/samples
    猜你喜欢
    • 2021-05-15
    • 1970-01-01
    • 2015-01-15
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 2018-03-29
    相关资源
    最近更新 更多