【问题标题】:Text alignment in textbox in phpwordphpword中文本框中的文本对齐
【发布时间】:2018-09-29 13:37:31
【问题描述】:

目前我正在努力解决phpword文本框中的对齐问题

我无法执行左对齐、右对齐和居中。

$textbox = 
    $section->addTextBox(
        array(
           'alignment'    => \PhpOffice\PhpWord\SimpleType\Jc::CENTER,
            'width'       => 460,
            'height'      => 100,
            'borderSize'  => 1,
            'borderColor' => '000',

        )
    );

$textbox->addText("Form No. SH-1", array('align'=>'center'));
$textbox->addText('SHARE CERTIFICATE.', $fontStyle2);
$cell = $textbox->addTable()->addRow()->addCell();
$cell->addText('Pursuant to sub-section 3 of section 46 of the Companies Act, 2013 and rule 5-2 of the Companies Share Capital and Debenture Rules, 2014', $fontStyle2);

如果有人知道,我需要将上面的文字放在中心,让我知道

【问题讨论】:

    标签: laravel phpword


    【解决方案1】:

    addText函数的第二个参数是字体样式,第三个参数是对齐规则所属的段落样式。所以你只需要将对齐规则作为第三个参数正确传递即可:

    $textbox->addText("Form No. SH-1", null, array('align'=>'center'));
    

    【讨论】:

      【解决方案2】:
      1. 为您的新 $phpWord 类定义一个段落样式,如下所示:
      $phpWord->addParagraphStyle('Paragraph', array('bold' => true , 'align' => 'center' ));
      
      1. 像这样向文本框添加文本:
      $textbox->addText('Hello World' , null, 'Paragraph' );
      

      【讨论】:

        【解决方案3】:

        使用对齐方式:

        $section->addText('Hello Stackoverflow!', [], [ 'align' => \PhpOffice\PhpWord\Style\Alignment::ALIGN_CENTER ]);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-05-06
          • 1970-01-01
          • 2015-07-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-15
          • 1970-01-01
          相关资源
          最近更新 更多