Patric Patric - 8 months ago 52
C# Question

OpenXML - Bullet Points get transformed to numbered list when merging documents

I have two documents that I try to merge partially.

I take some parts from document A that are inside a RTF content control and copy all child elements of the

of the content control to another
in document B using AppendChild and CloneNode(true) (deep cloning):

foreach (var srcChildElement in sourceDocumentSdtContentBlockNode.ChildElements)

The problem is, that if the content (list items) in my source document A is formatted with bullet points the result in document B will be numbered list items.

Why isn't the resulting style like in the source when I clone it? I thought it would just keep its style as I don't manipulate it. In document B there seems also no to be a formatting issue. I can manually insert bullets or a numbered list without a problem.

I even created two completly new word documents and the same thing happend, so it is surely not some issue with the existing files.

I found out that there is a separate numbering definition in a document ( which is not part of the node I copy. When I clone the node this information is not included at it is in a separate numbering definition. Is there a way to copy a node to a new document and tell it to retain the numbering styles from the numbering definition? The other option would be to manually check if the cloned node contains a
element and if yes to extract also the definition (including changing and reassigning the IDs) - would prefer a less complex way to copy an element and hope there is one :-)

Any ideas?

Answer Source

Well, I did manage to solve this. As already mentioned the Numbering information is stored in a separate part (or file inside the document zip):

From the NumberingDefinitions (in NumberingPart) of the source I copied the necessary (where there is a numPr inside a paragraph). To the target file by lookup up the numId of the numPr.

I cloned the num element and also the corresponding abstractNum element to the target. Doing this I also replaced the IDs (incremented all by 1 using the existing element IDs in the target) like numId, abstractNumId and nsid (hex value) to make sure there won't be any conflicts.

Was a bit work but very doable.