How to Merge Paragraphs

Let’s say the document looks like this:

Hello, my name is Jeff.**
I am happy.

We want to merge the two paragraphs, so that the output is this:

Hello, my name is Jeff.**I am happy.

(The ** are spaces)

Is there a built-in method for this?

Hi Jeff,

Thanks for your inquiry. Please find a couple of input/output Word documents here with this post and try executing the following code to achieve this:

Document doc = new Document(MyDir + @"in.docx");
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
Paragraph para1 = (Paragraph) paragraphs[0];
Paragraph para2 = (Paragraph) paragraphs[1];
foreach(Node node in para2)
{
    para1.AppendChild(node.Clone(true));
}
para2.Remove();
doc.Save(MyDir + @"out.docx");

I hope, this helps.

Best regards,

Thanks, Awais.