2
votes

I am wondering if someone can help. I have document with several content controls within it. Each content control contains lists or sometime single parapgraphs with styling.

Depending upon certain login I want to copy the entire content control or the content of the content control and paste it into another document.

In short, is there a way to copy and paste content controls between documents preserving styles using OpenXML?

Any help with be highly appreciated.

Thanks in advance.

Ashwin

1

1 Answers

0
votes

OpenXML is basically a collection of XML DOMs (just as the underlying DOCX file is a zip file containing a bunch of XML files). So it's not copy/paste as the term is generally meant.

You can copy a node (and its children) from one OpenXML to insert/add to the other. But it is not necessarily simple. For example, if the copied node has a paragraph with a style that does not exist in the destination OpenXML, you need to copy that style's node (and children) too. Same for fonts, lists, etc.

For content controls with simple content (styles/fonts not set or exist in both), this is pretty easy. But the cases where there's something you missed, those you need to address. I know this is not the most specific help, but what you have to handle is highly dependent on what is in your content control. For example, if you have a bitmap in one, then the bitmap, which is a distinct object in the OpenXML, also has to be copied.