How To: Create New Paragraph Style
The following example shows how to create a paragraph style.
To create a paragraph style, follow the steps below.
- Create a new paragraph style using the ParagraphStyleCollection.CreateNew method.
- Specify the required style settings using the corresponding ParagraphStyle instance properties.
- Add it to the ParagraphStyleCollection, accessible through the Document.ParagraphStyles property. To do that, use the ParagraphStyleCollection.Add method. The following code snippet creates a new paragraph style via the ParagraphStyleCollection.CreateNew method, specifies style settings, adds it to the document style collection and applies the style to the currently selected paragraph.
document.LoadDocument("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;