Click or drag to resize

Element Class

Represents a base class for all document elements.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentElement
    More...

Namespace:  SautinSoft.Document
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.7.4.3 (3.7.4.3)
Syntax
public abstract class Element

The Element type exposes the following members.

Properties
  NameDescription
Public propertyContent
Gets the ContentRange of the current element.
Public propertyDocument
Gets the owner document.
Public propertyElementType
Gets the ElementType of this element instance.
Public propertyNextSibling
Gets the next Element sibling.
Public propertyParent
Gets the parent of this element instance.
Public propertyParentCollection
Gets the ElementCollection that contains this element instance.
Public propertyPreviuosSibling
Gets the previous Element sibling.
Top
Methods
  NameDescription
Public methodCode exampleClone
Clones this element instance.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodCode exampleGetChildElements(Boolean)
Gets the child elements.
Public methodCode exampleGetChildElements(Boolean, ElementType)
Gets the child elements filtered by ElementType.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
Inserts a new Run (Text element) at the start of each paragraph in C#
using System;
using SautinSoft.Document;
using SautinSoft.Document.Tables;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            InsertParagraphCount();
        }
        /// <summary>
        /// Inserts a new Run (Text element) at the start of each paragraph.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/elementcollection-insert.php
        /// </remarks>
        static void InsertParagraphCount()
        {
            string filePath = @"..\..\example.docx";
            DocumentCore dc = DocumentCore.Load(filePath);
            int paragraphNum = 1;
            foreach (Element el in dc.Sections[0].GetChildElements(false))
            {
                if (el is Paragraph)
                {
                    // Insert a new Run into Paragraph.InlineCollection 'Inlines'.
                    // InlineCollection is descendant of the base abstract class ElementCollection.
                    (el as Paragraph).Inlines.Insert(0, new Run(dc, "Paragraph " + paragraphNum.ToString() + " - ", new CharacterFormat() { BackgroundColor = Color.Orange, FontColor = Color.White }));
                    paragraphNum++;
                }
            }
            dc.Save("Result.docx");

            // Show the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("Result.docx") { UseShellExecute = true });
        }
    }
}
Inserts a new Run (Text element) at the start of each paragraph in VB.Net
Imports System
Imports SautinSoft.Document
Imports SautinSoft.Document.Tables

Module Sample
    Sub Main()
        InsertParagraphCount()
    End Sub

    ''' <summary>
    ''' Inserts a new Run (Text element) at the start of each paragraph.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/elementcollection-insert.php
    ''' </remarks>
    Sub InsertParagraphCount()
        Dim filePath As String = "..\example.docx"
        Dim dc As DocumentCore = DocumentCore.Load(filePath)
        Dim paragraphNum As Integer = 1
        For Each el As Element In dc.Sections(0).GetChildElements(False)
            If TypeOf el Is Paragraph Then
                ' Insert a new Run into Paragraph.InlineCollection 'Inlines'.
                ' InlineCollection is descendant of the base abstract class ElementCollection.
                TryCast(el, Paragraph).Inlines.Insert(0, New Run(dc, "Paragraph " & paragraphNum.ToString() & " - ", New CharacterFormat() With {
                        .BackgroundColor = Color.Orange,
                        .FontColor = Color.White
                    }))
                paragraphNum += 1
            End If
        Next el
        dc.Save("Result.docx")

        ' Show the result.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("Result.docx") With {.UseShellExecute = True})
    End Sub
End Module
See Also
Inheritance Hierarchy