Back to Devexpress

TC

officefileapi-15299-word-processing-document-api-fields-field-codes-tc.md

latest2.0 KB
Original Source

TC

  • Mar 28, 2025
  • 2 minutes to read

Non-MailMerge field

{ TC “entry text” [switches] }

Specifies the text and page number for a table of contents entry, which is used by a TOC.

The TC field supports the following switches:

SwitchDescription
\f identifierThe type of items collected in a particular contents list. Use a unique type identifier for each type of list. This switch is required for including into corresponding TOC.
\l “level number”The level of the TC entry. If no level is specified, level 1 is assumed.
csharp
using (var wordProcessor = new RichEditDocumentServer()) {
wordProcessor.LoadDocument("Documents//Table of Contents.docx");
int j = 1;

// Mark every chapter title in the document by the TC field
for (int i = 0; i < wordProcessor.Document.Paragraphs.Count; i++) {
    string var = wordProcessor.Document.GetText(wordProcessor.Document.Paragraphs[i].Range);

    if (var.Contains("CHAPTER ")) {
        Field field = wordProcessor.Document.Fields.Create(wordProcessor.Document.Paragraphs[i].Range.Start, String.Format("TC {0} \\f bvz ", j));
        wordProcessor.Document.Fields.Update();
        j++;
    }
  } 
}
vb
Using wordProcessor = New RichEditDocumentServer()
wordProcessor.LoadDocument("Documents//Table of Contents.docx")

Dim j As Integer = 1

' Mark every chapter title in the document by the TC field
For i As Integer = 0 To wordProcessor.Document.Paragraphs.Count - 1
    Dim var As String = wordProcessor.Document.GetText(wordProcessor.Document.Paragraphs(i).Range)

    If var.Contains("CHAPTER ") Then
        Dim field As Field = wordProcessor.Document.Fields.Create(wordProcessor.Document.Paragraphs(i).Range.Start, String.Format("TC {0} \f bvz ", j))
        wordProcessor.Document.Fields.Update()
        j += 1
    End If
Next i
End Using