Back to Devexpress

Paragraph.OutlineLevel Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-paragraph-2c1c176d.md

latest5.0 KB
Original Source

Paragraph.OutlineLevel Property

Gets or sets the outline level of a paragraph.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
public abstract int OutlineLevel { get; set; }
vb
Public MustOverride Property OutlineLevel As Integer

Property Value

TypeDescription
Int32

An integer specifying the level number, or null to indicate a mix of values.

|

Remarks

Outline levels are used to build a table of contents without changing the appearance of your text.

When a document is exported to HTML with default settings, the outline level specifies the tag in which the paragraph is enclosed. Outline levels from 1 to 6 result in H1 - H6 tags respectively. Paragraphs with outline levels higher than 6 are exported as text enclosed in a <P> tag. You can set the HtmlDocumentExporterOptions.IgnoreParagraphOutlineLevel option to true to export all paragraphs using only <P> tags, disregarding their outline levels.

Example

csharp
using (var wordProcessor = new RichEditDocumentServer()) {
wordProcessor.LoadDocument("Documents//Table of Contents.docx");

// Set the outline level to every chapter title in the document
for (int i = 0; i < wordProcessor.Document.Paragraphs.Count; i++) {
    string var = wordProcessor.Document.GetText(wordProcessor.Document.Paragraphs[i].Range);
    if (var.Contains("CHAPTER "))
    {
        wordProcessor.Document.Paragraphs[i].OutlineLevel = 2;
    }
  }
}
vb
Using wordProcessor = New RichEditDocumentServer()

    wordProcessor.LoadDocument("Documents//Table of Contents.docx")

    ' Set the outline level to every chapter title in the document
    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
            wordProcessor.Document.Paragraphs(i).OutlineLevel = 2
        End If
    Next i
End Using

The following code snippets (auto-collected from DevExpress Examples) contain references to the OutlineLevel property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-richedit-table-of-contents-practical-guide/CS/Form1.cs#L57

csharp
SearchForTOCEntries(delegate(DocumentPosition location, int level) {
    Document.Paragraphs.Get(location).OutlineLevel = level;
});

word-processing-table-of-contents-practical-guide/CS/Program.cs#L64

csharp
SearchForTOCEntries(document, delegate (DocumentPosition location, int level) {
    document.Paragraphs.Get(location).OutlineLevel = level;
});

winforms-richedit-table-of-contents-practical-guide/VB/Form1.vb#L62

vb
Private Sub AssignOutlineLevels()
    SearchForTOCEntries(Sub(ByVal location, ByVal level) Document.Paragraphs.Get(location).OutlineLevel = level)
End Sub

word-processing-table-of-contents-practical-guide/VB/Program.vb#L60

vb
SearchForTOCEntries(document, Sub(location, level)
                                  document.Paragraphs.[Get](location).OutlineLevel = level
                              End Sub)

See Also

Paragraph Class

Paragraph Members

DevExpress.XtraRichEdit.API.Native Namespace