I am afraid that with the current version this will be impossible. I do not have a deep understanding of this library, but looking at the code, I found that the textRun class consists only of the addText and addLink .
But I also need this function, along with several others, so I'm going to write it myself and create a transfer request to include it in the next version (if any).
Basically, you can do this by changing the textRun class, adding the addLineBreak method (similar to the way in the section class), and then changing the Base.php class to create the corresponding elements in the final document.
In Docx xml, these linear brakes are similar to the html br tag, but the previous text should be closed and reopened after using break as follows:
<w:r> <w:t>This is</w:t> <w:br/> <w:t xml:space="preserve"> a simple sentence.</w:t> </w:r>
instead of just doing
<w:r> <w:t>This is<w:br /> a simple sentence</w:t> </w:r>
So in Base.php you need to change the behavior to create this block of code.
Hope this was helpful!
EDIT
I realized that implementing this is very simple. In textRun.php just add this method:
public function addTextBreak($count = 1) { for($i=1; $i<=$count; $i++) { $this->_elementCollection[] = new PHPWord_Section_TextBreak(); } }
and in Base.php in the Base.php method at the end of this method add this condition:
elseif($element instanceof PHPWord_Section_TextBreak) { $objWriter->writeElement('w:br'); }
source share