Insert in existing document

Nov 29, 2013 at 8:50 AM
Hi,

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


Thanks,
Torsten
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);

doc.SaveAs("test2.docx");
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);
doc.Paragraphs[index].InsertParagraphAfterSelf(para);
Thank you!