Represents a Table of Entries field, such as Table of Contents, Table of Figures,
Table of Authorities, Index or Bibliography.
Inheritance Hierarchy Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.12.16
Syntax public sealed class TableOfEntries : Block,
IContentElement
Public NotInheritable Class TableOfEntries
Inherits Block
Implements IContentElement
The TableOfEntries type exposes the following members.
Constructors Properties Methods | Name | Description |
---|
| Clone |
Clones this element instance.
|
| Update |
Performs an update on TOC (Table of Contents) field.
|
TopExample See Developer Guide: Create a document with table of content
Create a document with table of content using C#
using System;
using System.Linq;
using SautinSoft.Document;
namespace Example
{
class Program
{
static void Main(string[] args)
{
TOC();
}
public static void TOC()
{
string resultFile = "Table-Of-Contents.docx";
DocumentCore dc = new DocumentCore();
ParagraphStyle Heading1Style = (ParagraphStyle)Style.CreateStyle(StyleTemplateType.Heading1, dc);
dc.Styles.Add(Heading1Style);
ParagraphStyle Heading2Style = (ParagraphStyle)Style.CreateStyle(StyleTemplateType.Heading2, dc);
dc.Styles.Add(Heading2Style);
Section section = new Section(dc);
dc.Sections.Add(section);
section.Blocks.Add(new Paragraph(dc, "Table of Contents"));
section.Blocks.Add(new TableOfEntries(dc, FieldType.TOC));
section.Blocks.Add(new Paragraph(dc, "The end."));
section.Blocks.Add(
new Paragraph(dc,
new SpecialCharacter(dc, SpecialCharacterType.PageBreak)));
section.Blocks.Add(
new Paragraph(dc, "Chapter 1")
{
ParagraphFormat =
{
Style = Heading1Style
}
});
section.Blocks.Add(
new Paragraph(dc, String.Format("Subchapter 1-1"))
{
ParagraphFormat =
{
Style = Heading2Style
}
});
section.Blocks.Add(
new Paragraph(dc,
"�Document .Net� will help you in development of applications which operates with DOCX, RTF, PDF and Text documents. After adding of the reference to (SautinSoft.Document.dll) - it's 100% C# managed assembly you will be able to create a new document, parse an existing, modify anything what you want."));
section.Blocks.Add(
new Paragraph(dc,
new SpecialCharacter(dc, SpecialCharacterType.PageBreak)));
section.Blocks.Add(
new Paragraph(dc, "Chapter 2")
{
ParagraphFormat =
{
Style = Heading1Style
}
});
section.Blocks.Add(
new Paragraph(dc, String.Format("Subchapter 2-1"))
{
ParagraphFormat =
{
Style = Heading2Style
}
});
section.Blocks.Add(
new Paragraph(dc,
"Requires only .Net 4.0 or above. Our product is compatible with all .Net languages and supports all Operating Systems where .Net Framework can be used. Note that �Document .Net� is entirely written in managed C#, which makes it absolutely standalone and an independent library. Of course, No dependency on Microsoft Word."));
var toc = (TableOfEntries)dc.GetChildElements(true, ElementType.TableOfEntries).FirstOrDefault();
toc.Update();
dc.GetPaginator(new PaginatorOptions() { UpdateFields = true });
dc.Save(resultFile);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultFile) { UseShellExecute = true });
}
}
}
Create a document with table of content using VB.Net
Option Infer On
Imports System
Imports System.Linq
Imports SautinSoft.Document
Module Sample
Sub Main()
TOC()
End Sub
Sub TOC()
Dim resultFile As String = "Table-Of-Contents.docx"
Dim dc As New DocumentCore()
Dim Heading1Style As ParagraphStyle = CType(Style.CreateStyle(StyleTemplateType.Heading1, dc), ParagraphStyle)
dc.Styles.Add(Heading1Style)
Dim Heading2Style As ParagraphStyle = CType(Style.CreateStyle(StyleTemplateType.Heading2, dc), ParagraphStyle)
dc.Styles.Add(Heading2Style)
Dim section As New Section(dc)
dc.Sections.Add(section)
section.Blocks.Add(New Paragraph(dc, "Table of Contents"))
section.Blocks.Add(New TableOfEntries(dc, FieldType.TOC))
section.Blocks.Add(New Paragraph(dc, "The end."))
section.Blocks.Add(New Paragraph(dc, New SpecialCharacter(dc, SpecialCharacterType.PageBreak)))
section.Blocks.Add(New Paragraph(dc, "Chapter 1") With {
.ParagraphFormat = New ParagraphFormat With
{.Style = Heading1Style}
})
section.Blocks.Add(New Paragraph(dc, String.Format("Subchapter 1-1")) With {
.ParagraphFormat = New ParagraphFormat With
{.Style = Heading2Style}
})
section.Blocks.Add(New Paragraph(dc, "�Document .Net� will help you in development of applications which operates with DOCX, RTF, PDF and Text documents. After adding of the reference to (SautinSoft.Document.dll) - it's 100% C# managed assembly you will be able to create a new document, parse an existing, modify anything what you want."))
section.Blocks.Add(New Paragraph(dc, New SpecialCharacter(dc, SpecialCharacterType.PageBreak)))
section.Blocks.Add(New Paragraph(dc, "Chapter 2") With {
.ParagraphFormat = New ParagraphFormat With
{.Style = Heading1Style}
})
section.Blocks.Add(New Paragraph(dc, String.Format("Subchapter 2-1")) With {
.ParagraphFormat = New ParagraphFormat With
{.Style = Heading2Style}
})
section.Blocks.Add(New Paragraph(dc, "Requires only .Net 4.0 or above. Our product is compatible with all .Net languages and supports all Operating Systems where .Net Framework can be used. Note that �Document .Net� is entirely written in managed C#, which makes it absolutely standalone and an independent library. Of course, No dependency on Microsoft Word."))
Dim toc_Renamed = CType(dc.GetChildElements(True, ElementType.TableOfEntries).FirstOrDefault(), TableOfEntries)
toc_Renamed.Update()
dc.GetPaginator(New PaginatorOptions() With {.UpdateFields = True})
dc.Save(resultFile)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(resultFile) With {.UseShellExecute = True})
End Sub
End Module
See Also