Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bolding, spacing and indenting text in phpWord

Tags:

php

phpword

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?

like image 838
Benjamin Avatar asked Oct 27 '25 16:10

Benjamin


1 Answers

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)
    )
  );
like image 193
ejuhjav Avatar answered Oct 29 '25 06:10

ejuhjav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!