Class WParagraphFormat
Represents the formatting options of the paragraph in the Word document.
Implements
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class WParagraphFormat : FormatBase, IXDLSSerializable
Examples
The following example illustrates how to apply various paragraph formatting options.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Add new text to the paragraph
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " +
"Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.");
//After spacing, back color, borders, contextual spacing
paragraph.ParagraphFormat.AfterSpacing = 18f;
paragraph.ParagraphFormat.BackColor = Color.LightGray;
paragraph.ParagraphFormat.Bidi = true;
paragraph.ParagraphFormat.Borders.BorderType = BorderStyle.Dot;
paragraph.ParagraphFormat.Borders.Color = Color.Maroon;
paragraph.ParagraphFormat.Borders.LineWidth = 0.5f;
paragraph.ParagraphFormat.ContextualSpacing = true;
paragraph = section.AddParagraph();
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " +
"Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.");
//column break, firstline indent, alignment
paragraph.ParagraphFormat.ColumnBreakAfter = true;
paragraph.ParagraphFormat.FirstLineIndent = 12;
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.JustifyHigh;
paragraph = section.AddParagraph();
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " +
"Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.");
//Hanging indent, keep, left indent, line spacing, keep follow
paragraph.ParagraphFormat.FirstLineIndent = -12;
paragraph.ParagraphFormat.Keep = true;
paragraph.ParagraphFormat.LeftIndent = 10;
paragraph.ParagraphFormat.LineSpacing = 2;
paragraph.ParagraphFormat.LineSpacingRule = LineSpacingRule.AtLeast;
paragraph.ParagraphFormat.KeepFollow = true;
paragraph = section.AddParagraph();
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " +
"Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.");
//Mirror indent, outline level, page break
paragraph.ParagraphFormat.MirrorIndents = true;
paragraph.ParagraphFormat.OutlineLevel = OutlineLevel.Level2;
paragraph.ParagraphFormat.PageBreakAfter = true;
paragraph = section.AddParagraph();
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " +
"Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.");
//Right indent, auto spacing
paragraph.ParagraphFormat.RightIndent = 10;
paragraph.ParagraphFormat.SpaceAfterAuto = true;
paragraph.ParagraphFormat.SpaceBeforeAuto = true;
paragraph = section.AddParagraph();
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " +
"Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.");
//Auto hyphens, window control, before spacing, page break
paragraph.ParagraphFormat.SuppressAutoHyphens = true;
paragraph.ParagraphFormat.WidowControl = true;
paragraph.ParagraphFormat.BeforeSpacing = 18f;
paragraph.ParagraphFormat.PageBreakBefore = true;
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Add new text to the paragraph
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " & "Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.")
'After spacing, back color, borders, contextual spacing
paragraph.ParagraphFormat.AfterSpacing = 18.0F
paragraph.ParagraphFormat.BackColor = Color.LightGray
paragraph.ParagraphFormat.Bidi = True
paragraph.ParagraphFormat.Borders.BorderType = BorderStyle.Dot
paragraph.ParagraphFormat.Borders.Color = Color.Maroon
paragraph.ParagraphFormat.Borders.LineWidth = 0.5F
paragraph.ParagraphFormat.ContextualSpacing = True
paragraph = section.AddParagraph()
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " & "Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.")
'column break, firstline indent, alignment
paragraph.ParagraphFormat.ColumnBreakAfter = True
paragraph.ParagraphFormat.FirstLineIndent = 12
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.JustifyHigh
paragraph = section.AddParagraph()
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " & "Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.")
'Hanging indent, keep, left indent, line spacing, keep follow
paragraph.ParagraphFormat.FirstLineIndent = -12
paragraph.ParagraphFormat.Keep = True
paragraph.ParagraphFormat.LeftIndent = 10
paragraph.ParagraphFormat.LineSpacing = 2
paragraph.ParagraphFormat.LineSpacingRule = LineSpacingRule.AtLeast
paragraph.ParagraphFormat.KeepFollow = True
paragraph = section.AddParagraph()
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " & "Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.")
'Mirror indent, outline level, page break
paragraph.ParagraphFormat.MirrorIndents = True
paragraph.ParagraphFormat.OutlineLevel = OutlineLevel.Level2
paragraph.ParagraphFormat.PageBreakAfter = True
paragraph = section.AddParagraph()
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " & "Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.")
'Right indent, auto spacing
paragraph.ParagraphFormat.RightIndent = 10
paragraph.ParagraphFormat.SpaceAfterAuto = True
paragraph.ParagraphFormat.SpaceBeforeAuto = True
paragraph = section.AddParagraph()
paragraph.AppendText("Paragraphs are the basic elements of the Word document. It can contain text and images. " & "Paragraphs are the basic elements of the Word document. It can contain text and images. Paragraphs are the basic elements of the Word document. It can contain text and images.")
'Auto hyphens, window control, before spacing, page break
paragraph.ParagraphFormat.SuppressAutoHyphens = True
paragraph.ParagraphFormat.WidowControl = True
paragraph.ParagraphFormat.BeforeSpacing = 18.0F
paragraph.ParagraphFormat.PageBreakBefore = True
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
Constructors
WParagraphFormat()
Initializes a new instance of the WParagraphFormat class.
Declaration
public WParagraphFormat()
WParagraphFormat(IWordDocument)
Initializes a new instance of the WParagraphFormat class with the specified IWordDocument instance.
Declaration
public WParagraphFormat(IWordDocument document)
Parameters
Type | Name | Description |
---|---|---|
IWordDocument | document | The IWordDocument instance. |
Properties
AfterSpacing
Gets or sets the spacing (in points) after the paragraph.
Declaration
public float AfterSpacing { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the spacing value. |
BackColor
Gets or sets the background color of the paragraph.
Declaration
public Color BackColor { get; set; }
Property Value
Type | Description |
---|---|
System.Drawing.Color | The System.Drawing.Color for background. |
BeforeSpacing
Gets or sets the spacing (in points) before the paragraph.
Declaration
public float BeforeSpacing { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the spacing value. |
Bidi
Gets or sets a value indicating whether the paragraph is right-to-left.
Declaration
public bool Bidi { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the paragraph is right to left; otherwise, false. |
Borders
Gets the Borders collection that represents all the borders for the paragraph.
Declaration
public Borders Borders { get; }
Property Value
Type |
---|
Borders |
ColumnBreakAfter
Gets or sets a value indicating whether there is column break after the paragraph.
Declaration
public bool ColumnBreakAfter { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the column break is forced after the paragraph; otherwise, false. |
ContextualSpacing
Gets or sets a value indicating whether to add space between the paragraphs of same style.
Declaration
public bool ContextualSpacing { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if not to have spacing; otherwise, false. |
FirstLineIndent
Gets or sets a float that represents the first line or hanging indent of the paragraph.
Declaration
public float FirstLineIndent { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The positive value is set to first line indent and negative value is set to hanging indent. |
HorizontalAlignment
Gets or sets the horizontal alignment for the paragraph.
Declaration
public HorizontalAlignment HorizontalAlignment { get; set; }
Property Value
Type | Description |
---|---|
HorizontalAlignment | The HorizontalAlignment member that specifies the type of alignment. |
Keep
Gets or sets a value indicating whether all lines in the paragraph are to remain on the same page.
Declaration
public bool Keep { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if all lines of the paragraph to remain on the same page; otherwise, false. |
KeepFollow
Gets or sets a value indicating whether the paragraph remains on the same page as the paragraph that follows it.
Declaration
public bool KeepFollow { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the current paragraph to remain on the same page as the paragraph that follows it; otherwise, false. |
LeftIndent
Gets or sets a float that represents the left indent(in points) for paragraph.
Declaration
public float LeftIndent { get; set; }
Property Value
Type |
---|
System.Single |
LineSpacing
Gets or sets the line spacing(in points) for the paragraph.
Declaration
public float LineSpacing { get; set; }
Property Value
Type |
---|
System.Single |
LineSpacingRule
Gets or sets line spacing rule of the paragraph.
Declaration
public LineSpacingRule LineSpacingRule { get; set; }
Property Value
Type | Description |
---|---|
LineSpacingRule | The LineSpacingRule member that specifies the line spacing rule. |
MirrorIndents
Gets or sets a value indicating whether the left and right indents are of same width.
Declaration
public bool MirrorIndents { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if to have mirror indents; otherwise, false. |
OutlineLevel
Gets or sets the outline level for the paragraph.
Declaration
public OutlineLevel OutlineLevel { get; set; }
Property Value
Type | Description |
---|---|
OutlineLevel | The OutlineLevel member that specifies the outline level. |
PageBreakAfter
Gets or sets a value indicating whether there is page break after the paragraph.
Declaration
public bool PageBreakAfter { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if a page break is forced after the paragraph; otherwise, false. |
PageBreakBefore
Gets or sets a value indicating whether there is a page break before the paragraph.
Declaration
public bool PageBreakBefore { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if a page break is forced before the paragraph; otherwise, false. |
RightIndent
Gets or sets the float that represents the right indent for paragraph.
Declaration
public float RightIndent { get; set; }
Property Value
Type |
---|
System.Single |
SpaceAfterAuto
Gets or sets a value indicating whether Word automatically sets the amount of spacing after the paragraph.
Declaration
public bool SpaceAfterAuto { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if spacing after is automatic; otherwise, false. |
SpaceBeforeAuto
Gets or sets a value indicating whether Word automatically sets the amount of spacing before the paragraph.
Declaration
public bool SpaceBeforeAuto { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if spacing before is automatic; otherwise, false. |
SuppressAutoHyphens
Gets or sets a value that indicates whether automatic hyphenation of words is enabled or disabled.
Declaration
public bool SuppressAutoHyphens { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if automatic hyphenation of words is enabled; otherwise, false. |
Tabs
Gets the TabCollection that represents the tabs for the specified paragraph. Read-only.
Declaration
public TabCollection Tabs { get; }
Property Value
Type |
---|
TabCollection |
WidowControl
Gets or sets a value indicating whether the first and last lines of the paragraph are to remain on the same page as the rest of the paragraph when Word repaginates the document.
Declaration
public bool WidowControl { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if the first and last lines of the paragraph are to remain on the same page; otherwise, false. |
Methods
ClearFormatting()
Clears the paragraph formatting applied
Declaration
public override void ClearFormatting()
Overrides
EnsureComposites()
Ensures the composites.
Declaration
protected override void EnsureComposites()
Overrides
GetDefComposite(Int32)
Gets the composite values.
Declaration
protected override FormatBase GetDefComposite(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key | The integer that specifies the key. |
Returns
Type | Description |
---|---|
FormatBase | The FormatBase object. |
Overrides
GetDefValue(Int32)
Returns the default values.
Declaration
protected override object GetDefValue(int key)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | key | The integer that specifies the key. |
Returns
Type | Description |
---|---|
System.Object | An object that specifies the default value. |
Overrides
ImportContainer(FormatBase)
Imports the container.
Declaration
protected void ImportContainer(FormatBase format)
Parameters
Type | Name | Description |
---|---|---|
FormatBase | format | The FormatBase object. |
ImportMembers(FormatBase)
Imports the members.
Declaration
protected override void ImportMembers(FormatBase format)
Parameters
Type | Name | Description |
---|---|---|
FormatBase | format | The FormatBase object. |
Overrides
InitXDLSHolder()
Registers child objects in XDSL holder.
Declaration
protected override void InitXDLSHolder()
Overrides
ReadXmlAttributes(IXDLSAttributeReader)
Reads object data from xml attributes.
Declaration
protected override void ReadXmlAttributes(IXDLSAttributeReader reader)
Parameters
Type | Name | Description |
---|---|---|
IXDLSAttributeReader | reader | The IXDLSAttributeReader object. |
Overrides
ReadXmlContent(IXDLSContentReader)
Reads object data from xml attributes.
Declaration
protected override bool ReadXmlContent(IXDLSContentReader reader)
Parameters
Type | Name | Description |
---|---|---|
IXDLSContentReader | reader | The IXDLSContentReader object. |
Returns
Type | Description |
---|---|
System.Boolean | The value indicating the presence of xml content. |
Overrides
WriteXmlAttributes(IXDLSAttributeWriter)
Writes object data as xml attributes.
Declaration
protected override void WriteXmlAttributes(IXDLSAttributeWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IXDLSAttributeWriter | writer | The IXDLSAttributeWriter object. |
Overrides
WriteXmlContent(IXDLSContentWriter)
Writes object data as inside xml element.
Declaration
protected override void WriteXmlContent(IXDLSContentWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IXDLSContentWriter | writer | The IXDLSContentWriter object. |