DocX
DocX copied to clipboard
InsertParagraphAfterSelf doesn't return new Paragraph
Hi,
I'm working on a templating engine for docx, in which I need to create new elements and deeply modify the xml. When I have my own Paragraph (not yet attached to the document) that i want to insert after some element (Table, Paragraph, etc) it returns the exact same element without document reference. I managed to workaround this issue by writting my own InsertParagraphAfter:
// Create paragraph wrapper
var newParagraph = _docX.InsertParagraph(); // Create paragraph with doc reference
_docX.RemoveParagraph(newParagraph); // Remove content but preserve the reference
// Attach XML content to the paragraph
table.Xml.AddAfterSelf(paragraphToInsert.Xml);
newParagraph.Xml = table.Xml.ElementsAfterSelf().First();
return newParagraph;
It would be nice to be able to instantiate a paragraph from XML and, when adding it to the document, populate the reference.
Thank you for workaround! We definitely need a fix here.