【发布时间】:2018-09-06 19:30:08
【问题描述】:
我正在尝试在 PHPWord 的单元格中垂直对齐文本。
$cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER);
适用于水平对齐,但我找不到垂直对齐的解决方案,有什么想法吗?
【问题讨论】:
标签: phpword
我正在尝试在 PHPWord 的单元格中垂直对齐文本。
$cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER);
适用于水平对齐,但我找不到垂直对齐的解决方案,有什么想法吗?
【问题讨论】:
标签: phpword
解决方案可能并不完美!
检查以下代码第 3 行的 spaceAfter 和 spaceBefore - 在文本前后添加空格。我分配了250,你可以提供你自己的值。
$table = $section->addTable(['borderSize' => 6]);
$table->addRow();
$table->addCell(2000)->addText("Text in the Cell",['name'=>'Times New Roman','size' => 12],['spaceAfter' => 250,'spaceBefore' => 250]);
【讨论】:
这行得通:
$cell = $table->addCell(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(1.25), [
'valign' => \PhpOffice\PhpWord\SimpleType\VerticalJc::BOTTOM
]);
$cell->addText('Text', null, [
'spaceBefore' => \PhpOffice\PhpWord\Shared\Converter::inchToTwip(0),
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::inchToTwip(0),
'align' => 'end'
]);
虽然,手册上说要使用这个:
'valign' => 'bottom'
顺便说一句,这些功能还有:
'vAlign' => \PhpOffice\PhpWord\SimpleType\VerticalJc::BOTTOM
'vAlign' => 'bottom'
因此我得出结论,Section 和 Cell 垂直对齐之间存在一些重叠。
【讨论】: