Represents a base class for all document elements.
Inheritance Hierarchy SystemObject SautinSoft.DocumentElement More Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.11.20
Syntax public abstract class Element
Public MustInherit Class Element
The Element type exposes the following members.
Properties Methods Example See Developer Guide: Inserts a new Run (Text element) at the start of each paragraph
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();
}
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)
{
(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");
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
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
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")
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("Result.docx") With {.UseShellExecute = True})
End Sub
End Module
See Also Inheritance Hierarchy