【问题标题】:PHPWord Vertical Alignment of text in a cellPHPWord在单元格中的文本垂直对齐
【发布时间】:2018-09-06 19:30:08
【问题描述】:

我正在尝试在 PHPWord 的单元格中垂直对齐文本。

$cellHCentered = array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER);

适用于水平对齐,但我找不到垂直对齐的解决方案,有什么想法吗?

【问题讨论】:

    标签: phpword


    【解决方案1】:

    解决方案可能并不完美!

    检查以下代码第 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]);
    

    【讨论】:

      【解决方案2】:

      这行得通:

              $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 垂直对齐之间存在一些重叠。

      【讨论】:

        猜你喜欢
        • 2018-04-27
        • 2017-09-04
        • 1970-01-01
        • 2019-05-03
        • 1970-01-01
        • 1970-01-01
        • 2011-07-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多