How to: Create New Paragraph Style
The following example shows how to create a paragraph style.
To create a paragraph style, perform the following steps:
- Create a new paragraph style using ParagraphStyleCollection.CreateNew method;
- Specify the required style settings using corresponding ParagraphStyle instance properties;
- Add it to the ParagraphStyleCollection, accessible through the Document.ParagraphStyles property. To do that, use the ParagraphStyleCollection.Add method.
Document document = server.Document;
document.LoadDocument("Documents\\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
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;