Represents a base class for all styles.
Inheritance Hierarchy Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.12.16
Syntax public abstract class Style
Public MustInherit Class Style
The Style type exposes the following members.
Properties | Name | Description |
---|
| BaseStyle |
Gets or sets the style on which this style is based.
|
| Document |
Gets the owner document.
|
| IsDefault |
When true, this style is the default for this style type.
|
| Name |
Gets or sets the name of the style.
|
| StyleType |
Gets the type of the style.
|
TopMethods Remarks
All document styles are contained in a
Styles
collection.
Example See Developer Guide: This sample shows how to work with styles
This sample shows how to work with styles in DocumentCore using C#
using SautinSoft.Document;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
Styles();
}
public static void Styles()
{
string docxPath = @"Styles.docx";
DocumentCore dc = new DocumentCore();
CharacterStyle characterStyle = new CharacterStyle("CharacterStyle1");
characterStyle.CharacterFormat.FontName = "Arial";
characterStyle.CharacterFormat.UnderlineStyle = UnderlineType.Wave;
characterStyle.CharacterFormat.Size = 18;
ParagraphStyle paragraphStyle = new ParagraphStyle("ParagraphStyle1");
paragraphStyle.CharacterFormat.FontName = "Times New Roman";
paragraphStyle.CharacterFormat.Size = 14;
paragraphStyle.ParagraphFormat.Alignment = HorizontalAlignment.Center;
dc.Styles.Add(characterStyle);
dc.Styles.Add(paragraphStyle);
dc.Sections.Add(
new Section(dc,
new Paragraph(dc,
new Run(dc, "Once upon a time, in a far away swamp, there lived an ogre named "),
new Run(dc, "Shrek") { CharacterFormat = { Style = characterStyle } },
new Run(dc, " whose precious solitude is suddenly shattered by an invasion of annoying fairy tale characters..."))
{ ParagraphFormat = { Style = paragraphStyle } }));
dc.Save(docxPath);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docxPath) { UseShellExecute = true });
}
}
}
This sample shows how to work with styles in DocumentCore using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
Sub Main()
Styles()
End Sub
Sub Styles()
Dim docxPath As String = "Styles.docx"
Dim dc As New DocumentCore()
Dim characterStyle As New CharacterStyle("CharacterStyle1")
characterStyle.CharacterFormat.FontName = "Arial"
characterStyle.CharacterFormat.UnderlineStyle = UnderlineType.Wave
characterStyle.CharacterFormat.Size = 18
Dim paragraphStyle As New ParagraphStyle("ParagraphStyle1")
paragraphStyle.CharacterFormat.FontName = "Times New Roman"
paragraphStyle.CharacterFormat.Size = 14
paragraphStyle.ParagraphFormat.Alignment = HorizontalAlignment.Center
dc.Styles.Add(characterStyle)
dc.Styles.Add(paragraphStyle)
Dim par As New Paragraph(dc)
par.ParagraphFormat.Style = paragraphStyle
dc.Sections.Add(New Section(dc, par))
par.Inlines.Add(New Run(dc, "Once upon a time, in a far away swamp, there lived an ogre named "))
Dim run As New Run(dc, "Shrek")
run.CharacterFormat.Style = characterStyle
par.Inlines.Add(run)
par.Inlines.Add(New Run(dc, " whose precious solitude is suddenly shattered by an invasion of annoying fairy tale characters..."))
dc.Save(docxPath)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(docxPath) With {.UseShellExecute = True})
End Sub
End Module
See Also