Back to Devexpress

How to: Create New Paragraph Style

officefileapi-116831-word-processing-document-api-examples-styles-how-to-create-new-paragraph-style.md

latest2.1 KB
Original Source

How to: Create New Paragraph Style

  • Sep 19, 2023

The following example shows how to create a paragraph style.

To create a paragraph style, perform the following steps:

View Example

csharp
Document document = server.Document;
document.LoadDocument("Documents\\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.Docx);
ParagraphStyle pstyle = document.ParagraphStyles["MyPStyle"];
if (pstyle == null)
{
    pstyle = document.ParagraphStyles.CreateNew();
    pstyle.Name = "MyPStyle";
    pstyle.LineSpacingType = ParagraphLineSpacing.Double;
    pstyle.Alignment = ParagraphAlignment.Center;
    document.ParagraphStyles.Add(pstyle);
}
document.Paragraphs[2].Style = pstyle;
vb
Dim document As Document = server.Document
document.LoadDocument("Documents\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.Docx)
Dim pstyle As ParagraphStyle = document.ParagraphStyles("MyPStyle")
If pstyle Is Nothing Then
    pstyle = document.ParagraphStyles.CreateNew()
    pstyle.Name = "MyPStyle"
    pstyle.LineSpacingType = ParagraphLineSpacing.Double
    pstyle.Alignment = ParagraphAlignment.Center
    document.ParagraphStyles.Add(pstyle)
End If
document.Paragraphs(2).Style = pstyle