Closed fil-filiposki closed 5 years ago
p.addLineBreak()
is the same as Shift + Enter
in Office Word (A new line in the current paragraph)
Hi Craig,
Thanks for your help, I have tried replacing '\n' with '+p.addLineBreak()+' however doesn't appear to be working. I have also tried other options such as '\r\n' & '\r' however also no luck. I do wonder how everybody else has been able to implement new lines in strings? I would have thought this would be necessary requirement for most word documents.
Any other ideas or workarounds you could suggest?
It isn't inline, you would do this:
var pObj = docx.createP();
pObj.addText('First Line');
pObj.addLineBreak();
pObj.addText('Second Line');
If you already had text with newlines simply split the string in to an array and loop over it to achieve the same effect.
Hi Craig,
Thanks for your help, I can confirm this works - for anybody else looking to do the same:
var string = 'test\ntesttest\n\ntesttesttest';
var split = string.split(/\n/);
var pObj = docx.createP();
for(var x of split){
pObj.addText(x);
pObj.addLineBreak();
}
I'll leave it open because I'll add an automatic support for this like I'm doing for pptx files. I'll be ready for version 0.6.3 (in a few days).
Implemented in 0.6.3
Hi,
It appears '\n' is replaced with a space when adding text for DOCX. How do you create a new line?
Example below:
Returns:
firstline nextline
I am using Officegen 0.4.5.