Bolding, spacing and indenting text in phpWord

社会主义新天地 提交于 2019-12-11 05:48:41

问题


I have some text that I want bold, separated from previous and subsequent paragraphs, and indented. I can't get all three properties to work together.

This works for bold and spaced:

$section = $phpWord->addSection();
$section->addText(
    'Re: Your Application for Post of Security Guard',
    array('bold' => true),
    array('space' => array('before' => 360, 'after' => 280))
  );

and this works for indented:

$section = $phpWord->addSection();
$section->addText(
    'Re: Your Application for Post of Security Guard',
   array('indentation' => array('left' => 540, 'right' => 120))
   );

but this doesn't work:

$section = $phpWord->addSection();
$section->addText(
    'Re: Your Application for Post of Security Guard',
    array('bold' => true),
    array('space' => array('before' => 360, 'after' => 280)),
    array('indentation' => array('left' => 540, 'right' => 120))
  );

Can anyone help me?


回答1:


The section addText function is:

$section->addText($text, [$fontStyle], [$paragraphStyle]);

i.e. the right way is to combine your paragraph styles into one array:

$section = $phpWord->addSection();
$section->addText(
    'Re: Your Application for Post of Security Guard',
    array('bold' => true),
    array(
        'space' => array('before' => 360, 'after' => 280), 
        'indentation' => array('left' => 540, 'right' => 120)
    )
  );


来源:https://stackoverflow.com/questions/40651897/bolding-spacing-and-indenting-text-in-phpword

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!