TOC 3 Style not being applied to table of contents

Hello,

I am appending an inner word document into an outer word doc.
Once I have appended I move to end of document, set the paragraph style to a custom style which has OutlineLevel.Level3 and use a DocumentBuilder to write some text.

The text is showing correctly in the table of contents but the expected “TOC 3” style does not get applied.

There is an outline level 1 which has the “TOC 1” style applied correctly.

Is there a way to ensure all TOC styles are applied?

I am calling UpdateFields and UpdatePageLayout but for some reason the “TOC 3” style is Arial instead of Calibri.

This does not happen when the OutlineLevel.Level3 is used without appending a document via AppendDocument method.

Sample code attached.
Zip contains an Output.docx file which shows the issue and png images where you can see the TOC 1 with correct font and level3 with wrong font.

Thanks
AsposeDocxToc.zip (503.9 KB)

@roberto.silva Not sure why, but for some reason MS Word inherits formatting from the target paragraph. If clear font and paragraph formatting, the problem disappears:

chapterBuilder.MoveToDocumentEnd();
chapterBuilder.Writeln();
// Clear formatting.
chapterBuilder.ParagraphFormat.ClearFormatting();
chapterBuilder.Font.ClearFormatting();
var style = outerDoc.Styles[customToc3];
chapterBuilder.ParagraphFormat.Style = style;
chapterBuilder.Write("level3 test");

Thanks that fixed most of the issues, something not quite right with the page numbers not being but that’s related with our TOC fonts changing to Calibri Light.
I have no idea why that happens?

@roberto.silva Could you please elaborate the problem. As I can see the page numbesr in the TOC are correct:

In the appended document page numbers are restarted, so level3 test has page number 1. If before appending document disable this options like this:

innerDoc.FirstSection.PageSetup.RestartPageNumbering = false;
outerDoc.AppendDocument(innerDoc, ImportFormatMode.UseDestinationStyles, importOptions);

page numbers in the TOC will be the following: