Hi
Sorry for delay. Please try using the following code snippet.
public void Test026()
{
Document srcDoc = new Document(@"Test026\MS PROP_Part (1).doc");
Document doc = new Document();
ImportStyle(doc.Styles[StyleIdentifier.Toc1], srcDoc.Styles[StyleIdentifier.Toc1]);
ImportStyle(doc.Styles[StyleIdentifier.Toc2], srcDoc.Styles[StyleIdentifier.Toc2]);
ImportStyle(doc.Styles[StyleIdentifier.Toc3], srcDoc.Styles[StyleIdentifier.Toc3]);
DocumentBuilder builder = new DocumentBuilder(doc);
// Insrt a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
// ……………………………………………………………….
doc.Save(@"Test026\out.doc");
}
private void ImportStyle(Style dstStyle, Style srcStyle)
{
dstStyle.Font.Name = srcStyle.Font.Name;
dstStyle.Font.Bold = srcStyle.Font.Bold;
dstStyle.Font.Size = srcStyle.Font.Size;
dstStyle.Font.AllCaps = srcStyle.Font.AllCaps;
dstStyle.ParagraphFormat.Alignment = srcStyle.ParagraphFormat.Alignment;
dstStyle.ParagraphFormat.LineSpacing = srcStyle.ParagraphFormat.LineSpacing;
dstStyle.ParagraphFormat.SpaceAfter = srcStyle.ParagraphFormat.SpaceAfter;
dstStyle.ParagraphFormat.SpaceBefore = srcStyle.ParagraphFormat.SpaceBefore;
dstStyle.ParagraphFormat.LeftIndent = srcStyle.ParagraphFormat.LeftIndent;
dstStyle.ParagraphFormat.RightIndent = srcStyle.ParagraphFormat.RightIndent;
dstStyle.ParagraphFormat.FirstLineIndent = srcStyle.ParagraphFormat.FirstLineIndent;
dstStyle.ParagraphFormat.LineSpacingRule = srcStyle.ParagraphFormat.LineSpacingRule;
dstStyle.ParagraphFormat.OutlineLevel = srcStyle.ParagraphFormat.OutlineLevel;
dstStyle.ParagraphFormat.SpaceAfterAuto = srcStyle.ParagraphFormat.SpaceAfterAuto;
dstStyle.ParagraphFormat.SpaceBeforeAuto = srcStyle.ParagraphFormat.SpaceBeforeAuto;
dstStyle.ParagraphFormat.TabStops.Clear();
for (int i = 0; i < srcStyle.ParagraphFormat.TabStops.Count; i++)
{
dstStyle.ParagraphFormat.TabStops.Add(srcStyle.ParagraphFormat.TabStops[i]);
}
}
I hope this could help you.
Best regards.