List level and heading style issues

Hello everyone,

I’m currently struggling with two issues that I can’t quite understand.

I have a target document that already contains formatting definitions, i.e., Heading1 through Heading9 are defined. Let’s say all the headings are set to have a blue font color. The document itself is empty and contains no actual content yet.

Then, I have another document that I want to insert into the target document. This source document has a Heading1 style that is formatted with a red font color and has an associated list level applied. This list level causes Heading1 paragraphs to be numbered, but without a dot, e.g., “1 Hello World”. This document contains both text and a heading formatted with Heading1 (red color and “1 Hello World” numbering).

In contrast, the target document’s Heading1 is configured with a blue font color and a different list level, which adds a dot after the number, i.e., “1. Hello World”.


Now to my problem:

When I insert the source document into the target document, all heading styles (like Heading1) in the target document get replaced by the ones from the inserted document. So in this case, Heading1 in the target document gets overridden by the red version from the source document.

However, if Heading1 had been used at least once in the target document before the insertion, then the style would not get overridden by the source document’s style.

I am using the following command to insert the document:

destinationDocument.appendDocument(tempDocument, ImportFormatMode.USE_DESTINATION_STYLES);

What also bothers me is that even if Heading1 was already used in the target document, the list level formatting from the inserted document seems to take precedence. So instead of “1. Hello World”, it still shows “1 Hello World”.

When I inspect the paragraph style afterwards, it correctly shows that it’s using Heading1, and the preview shows the correct formatting (“1. Heading 1”). But the actual numbering in the document is still wrong — until I re-apply the style manually, even though it’s already applied.

I would be very happy to receive help!

@DennisWall Try using our LowCode feature (Merger Class | Aspose.Words for .NET):

Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
    .From(inputDoc1)
    .From(inputDoc2)
    .To("output.docx")
    .Execute();

Otherwise, please attach the files and the code you are using to help us reproduce the problem.