A collection of Paragraph objects in a Range.
For a list of all members of this type, see Paragraphs Members.
System.Object
Aspose.Editor.Client.Paragraphs
[Visual Basic]
NotInheritable Public Class Paragraphs
[C#]public sealed class Paragraphs
Remarks
Use the Paragraphs property of the Range object to return a Paragraphs collection. You do not create instances of the Paragraphs class directly.
Use the Add method to add a new paragraph to a document. Alternatively use the InsertParagraph, InsertParagraphBefore or InsertParagraphAfter methods of the Range object to add new paragraphs to a document.
Use the Item property to return a single Paragraph object.
A Paragraphs collection is always "live". Any changes made to the document (possibly via other Paragraphs collections) are reflected in all existing Paragraphs collections.
This is a "live" collection of document elements so getting Count might sometimes have to recalculate the number of items. Consider caching the value of Count in time-critical loops.
Example
Demonstrates how to apply built-in style to paragraph.
[C#]
// Get range of the document
Range range = document.GetRange();
// Insert paragraph at document start
range.InsertParagraphBefore();
// Apply Heading 1 style to it
range.Paragraphs[0].StyleName = "Heading 1";
[Visual Basic]
' Get range of the document
Dim range As Range = document.GetRange()
' Insert paragraph at document start
range.InsertParagraphBefore()
' Apply Heading 1 style to it
range.Paragraphs(0).StyleName = "Heading 1"
Gets the first paragraph in the document and turns into bold and centered.
[C#]
Document doc = new Document(MyPath + "Welcome.xml");
Range docRange = doc.GetRange();
Paragraph para = docRange.Paragraphs[0];
Range paraRange = para.GetRange();
paraRange.Bold = true;
paraRange.ParagraphFormat.Alignment = ParagraphAlignment.Center;
doc.Save(MyPath + "ExRange.ParaRange Out.xml");
[Visual Basic]
Dim doc As New Document(MyPath & "Welcome.xml")
Dim docRange As Range = doc.GetRange()
Dim para As Paragraph = docRange.Paragraphs(0)
Dim paraRange As Range = para.GetRange()
paraRange.Bold = True
paraRange.ParagraphFormat.Alignment = ParagraphAlignment.Center
doc.Save(MyPath & "ExRange.ParaRange Out.xml")
Shows how to apply styles.
[C#]
// Create paragraph style
Style myStyle = document.Styles.Add("MyStyle", StyleType.Paragraph);
myStyle.ParagraphFormat.FirstLineIndent = 24f;
// Lets apply style to the 1st paragraph in the document.
Range range = document.GetRange();
range.Paragraphs[0].StyleName = myStyle.Name;
// Style is now applied.
Assert.AreEqual(myStyle.Name, range.Paragraphs[0].StyleName);
// This is how to remove all formatting including style and direct formatting.
range.ClearFormatting();
[Visual Basic]
' Create paragraph style
Dim myStyle As Style = document.Styles.Add("MyStyle", StyleType.Paragraph)
myStyle.ParagraphFormat.FirstLineIndent = 24f
' Lets apply style to the 1st paragraph in the document.
Dim range As Range = document.GetRange()
range.Paragraphs(0).StyleName = myStyle.Name
' Style is now applied.
Assert.AreEqual(myStyle.Name, range.Paragraphs(0).StyleName)
' This is how to remove all formatting including style and direct formatting.
range.ClearFormatting()Requirements
Namespace: Aspose.Editor.Client
Assembly: Aspose.Editor.Client (in Aspose.Editor.Client.dll)
See Also
Paragraphs Members | Aspose.Editor.Client Namespace | Range | Paragraph