DocX icon indicating copy to clipboard operation
DocX copied to clipboard

InsertParagraphAfterSelf doesn't return new Paragraph

Open isc30 opened this issue 7 years ago • 1 comments

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.

isc30 avatar Nov 02 '17 08:11 isc30

Thank you for workaround! We definitely need a fix here.

AlexLunyov avatar Jul 11 '22 12:07 AlexLunyov