PHPWord how to add text break / new line while in

2019-04-29 10:12发布

How can I add a text break or go to the next line/row while in a text run? I tried to just do $section->addTextBreak(2); while in the text run but it just added the breaks to the section after the text run. I also tried $textrun->addTextBreak(2); but it gave me a fatal error. Any responses would be greatly appreciated.

8条回答
仙女界的扛把子
2楼-- · 2019-04-29 10:59

The question was asked 3 years ago but I have the same problem and I found a solution. Maybe this can help new users of PHPWord.

To add a crlf in Word document the tag can help :

$section->addText('Some text <w:br/> another text in the line ');

I found the solution here : http://jeroen.is/phpword-line-breaks/

查看更多
狗以群分
3楼-- · 2019-04-29 10:59

Adding a newline in phpword has bothered me, and I finnaly found solution, by accident, so here it is: And this justifies the text.

$PHPWord->addParagraphStyle('pJustify', array('align' => 'both', 'spaceBefore' => 0, 'spaceAfter' => 0, 'spacing' => 0));
//add this style then append it to text below
$section->addText('something', 'textstyle', 'pJustify');
//the text behind this will be justified and will be in a new line, not in a new paragraph
$section->addText('behind', 'textstyle', 'pJustify');

This will output:

something

behind

查看更多
登录 后发表回答