-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new line in template #838
Comments
I just tried with "< w : b r / >\n" (without space) and it seems to work both in MS Office and LibreOffice. |
@antho2930 Your solution is working for me but new lines are prefixed with an intial whitespace. |
@antho2930 @SalvatorePollaci You need to replace |
How i can add |
Here's the true answer to "How to add newline while template processing" You can't just replace \n with The real solution is to always use a complex type instead of using strings. So in my function instead of returning a string I do this:
and in the template processor driver I use:
this will result in newlines and tab stops and other paragraph related things are preserved in the next lines! This allows you to create basic tables with tab stops and not worry about them breaking after the new lines. |
Works, but for me cause problems with justify content (extra spaces between words). Maybe is because is using soft lines instead of paragraph breaks like said here. Fallow ooxml i try to fix it with the using the bellow code:
This works for me with multiple spaces replaces and allow to keep using justify and custom alingments, styles if i need. |
I have tried ALL the posted decisions on github, stackoverflow, different sites, I was googling for 3 days and nothing worked. So I went to the docx document, renamed its extension to the zip, and checked the document xml schema. So there is a bit of code, that can be used for inserting a new line without text break bug: <?php
$textRun = new TextRun();
$textRun->addText('A long text here');
// new line
$textRun->addText('</w:t></w:r></w:p>
<w:p>
<w:pPr>
<w:contextualSpacing/>
<w:jc w:val="both"/>
<w:rPr>
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>
</w:rPr>
</w:pPr>
<w:r>
<w:t>');
// a second row
$textRun->addText('Another long text here');
// replace a variable
$doc->setComplexValue('Variable', $textRun); In my case I'm using Times New Roman, and justify text alignment. You can set your own options for the paragraph, but you should specify them in ooxml format using tags. Hope this helps somebody |
Worked like a charm, thanks a lot |
I'm using template processo for create a word document.
setValue method work fine, but i need set 3 strings in 3 lines.
String1
String2
String3
I have tried to add "\n"
String1\nString2\nString3
but this work fine ONLY with libreoffice, with microsoft office doesn't work fine.
I have tried to add '< w : b r / >' (without space) but dosen't work on libreoffice
Any suggestions?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: