TOC formatting in a Word document

Dear Sir or Madam,

We currently insert a TOC in our documents using the fields code:

            string fieldBody = string.Format("TC \"{0}\"\\f x", field);
            Run tocFieldRun = new Run(mOutputDocument) {Text = string.Empty};
            if (nodePara.ChildNodes != null && nodePara.ChildNodes.Count > 0)
            {
                AW.Node firstRun = nodePara.FirstChild;
                nodePara.InsertBefore(tocFieldRun, firstRun);
            }
            else
            {
                nodePara.AppendChild(tocFieldRun);
            }

How can we:

  1. Change tab leads in TOC (for dots, for example)
  2. Change the spacing between the lines in TOC?

Thank you in advance,
AlexAlex test-Annual Report-Alex test-Headers-Suffix (2).docx (209.6 KB)

@AlexanderNovickov You can configure appearance of TOC by modifying Toc1…Toc9 styles in the document. in your sample document there is only one level of TOC items, so you can edit only Toc1 style. For example see the following code:

Document doc = new Document(@"C:\Temp\in.docx");

Style toc1 = doc.Styles[StyleIdentifier.Toc1];
// Change tab leader
toc1.ParagraphFormat.TabStops[0].Leader = TabLeader.Dots;
// Change spaciing between pararaphs
toc1.ParagraphFormat.LineSpacing = 20;

doc.Save(@"C:\Temp\out.docx");

Hi Alexey,

Thank you, that’s what I was looking for.

Alex