This project has moved and is read-only. For the latest updates, please go here.

Insert in existing document

Nov 29, 2013 at 8:50 AM

is there a way to insert paragraphs into an existing document? As far as I can see, the InsertParagraph methods do an add.

Dec 3, 2013 at 6:20 AM
Yes, you can. Haven't tested this exact code, but it should work with something similar to this:

DocX doc = DocX.Load("test.docx");

Paragraph newParagraph = new Paragraph();
newParagraph.Text = "hello";

//Isnert paragraph after the last paragraph in the document:
doc.Paragraphs[doc.Paragraphs.Count - 1].InsertParagraphAfterSelf(newParagraph);

Dec 4, 2013 at 8:00 AM
The ctor of Paragraph is internal, but it works that way:
var para = doc.InsertParagraph(0, "hello", false);
Thank you!