Skip to main content
A newer version of this page is available. .

Paragraphs

  • 2 minutes to read

Overview

A Section consists of paragraphs. The Paragraph class represents the paragraph entity in the document model. You can access the collection of paragraphs in a document using the SubDocument.Paragraphs property. The Section.Paragraphs property gives you a collection of paragraphs in a particular section of a document.

To insert a paragraph at an arbitrary position, use the ParagraphCollection.Insert method accessible by Document.Paragraphs.Insert notation.

For the specified DocumentPosition, use the ReadOnlyParagraphCollection.Get method (Document.Paragraphs.Get(DocumentRange range) notation) to get the encompassing Paragraph.

Formatting

Paragraph formatting can be modified using the ParagraphProperties object accessible via the SubDocument.BeginUpdateParagraphs method. See also the Text Formatting topic.

document.BeginUpdate();
document.AppendText("Modified Paragraph\nNormal\nNormal");
document.EndUpdate();

//The target range is the first paragraph
DocumentPosition pos = document.Range.Start;
DocumentRange range = document.CreateRange(pos, 0);

// Create and customize an object  
// that sets character formatting for the selected range
ParagraphProperties pp = document.BeginUpdateParagraphs(range);
// Center paragraph
pp.Alignment = ParagraphAlignment.Center;
// Set triple spacing
pp.LineSpacingType = ParagraphLineSpacing.Multiple;
pp.LineSpacingMultiplier = 3;
// Set left indent at 0.5".
// Default unit is 1/300 of an inch (a document unit).
pp.LeftIndent = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.5f);
// Set tab stop at 1.5"
TabInfoCollection tbiColl = pp.BeginUpdateTabs(true);
TabInfo tbi = new DevExpress.XtraRichEdit.API.Native.TabInfo();
tbi.Alignment = TabAlignmentType.Center;
tbi.Position = DevExpress.Office.Utils.Units.InchesToDocumentsF(1.5f);
tbiColl.Add(tbi);
pp.EndUpdateTabs(tbiColl);

//Finalize modifications
// with this method call
document.EndUpdateParagraphs(pp);

Paragraph Text

To modify text of the paragraph, get its Paragraph.Range or any position(s) within that range and use SubDocument methods (for example, SubDocument.InsertRtfText, SubDocument.AppendText etc.) for the obtained DocumentRange object.