Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Description

Excerpt

The ParagraphFormatting class is used to specify formatting that should be applied to a paragraph. It also represents the paragraph formatting of named styles in the document.

Signature
C#
C#
 public sealed class ParagraphFormatting
Signature
vb.net
vb.net
Public NotInheritable Class ParagraphFormatting
Remarks

There are two ways to obtain an instance of this class: Create a new normal paragraph formatting object using the Document.CreateParagraphFormatting method or access an existing style's paragraph formatting information using the NamedStyle.ParagraphFormatting property. The ParagraphFormatting object that is returned can then be used in conjunction with methods in the Element class to create paragraphs with specific formatting.

The following example demonstrates both ways of getting paragraph formatting, first by retrieving the BodyText style's paragraph formatting from the document, second by retrieving a copy of the BodyText2 style's paragraph formatting. Then, some properties are set and the formatting is applied to a new paragraph.

Example
Code Block
csharp
csharp
titleC#

          //--- Get BodyText paragraph formatting from Document
          WordApplication app = new WordApplication();
          Document doc = app.Create();
          ParagraphFormatting bodyTextFormatting =
               doc.CreateParagraphFormatting();

          //--- Set some properties
          bodyTextFormatting.PageBreakBefore = true;
          bodyTextFormatting.TextJustification =
               ParagraphFormatting.Justification.Right;

          //--- Apply it to a new paragraph
          doc.InsertParagraphAfter(null, bodyTextFormatting);

          //--- Get paragraph formatting from BodyText2 Style
          WordApplication app = new WordApplication();
          Document doc = app.Create();
          ParagraphFormatting bodyText2Formatting =
               doc.Styles[NamedStyle.BuiltIn.BodyText2].ParagaphFormatting;

          //--- Set some properties
          bodyText2Formatting.PageBreakBefore = true;
          bodyText2Formatting.TextJustification =
               ParagraphFormatting.Justification.Right;

          //--- Apply it to a new paragraph
          doc.InsertParagraphAfter(null, bodyText2Formatting);
        
Code Block
vb.net
vb.net
titlevb.net

          '--- Get BodyText paragraph formatting from Document
          Dim app As New WordApplication()
          Dim doc As Document = app.Create()
          Dim bodyTextFormatting As ParagraphFormatting = _
               doc.CreateParagraphFormatting()

          '--- Set some properties
          bodyTextFormatting.PageBreakBefore = True
          bodyTextFormatting.TextJustification = _
               ParagraphFormatting.Justification.Right

          '--- Apply it to a new paragraph
          doc.InsertParagraphAfter(Nothing, bodyTextFormatting)

          '--- Get paragraph formatting from BodyText2 Style
          Dim app As New WordApplication()
          Dim doc As Document = app.Create()
          Dim bodyText2Formatting As ParagraphFormatting = _
               doc.Styles(NamedStyle.BuiltIn.BodyText2).ParagraphFormatting

          '--- Set some properties
          bodyText2Formatting.PageBreakBefore = True
          bodyText2Formatting.TextJustification = _
               ParagraphFormatting.Justification.Right

          '--- Apply it to a new paragraph
          doc.InsertParagraphAfter(Nothing, bodyText2Formatting)
        
Properties

Name

Description

AbsolutePositioning

Excerpt Include
ParagraphFormatting.AbsolutePositioning
ParagraphFormatting.AbsolutePositioning
nopaneltrue

AfterAutoSpacing

Excerpt Include
ParagraphFormatting.AfterAutoSpacing
ParagraphFormatting.AfterAutoSpacing
nopaneltrue

AllowAutoHyphenation

Excerpt Include
ParagraphFormatting.AllowAutoHyphenation
ParagraphFormatting.AllowAutoHyphenation
nopaneltrue

BeforeAutoSpacing

Excerpt Include
ParagraphFormatting.BeforeAutoSpacing
ParagraphFormatting.BeforeAutoSpacing
nopaneltrue

KeepLinesTogether

Excerpt Include
ParagraphFormatting.KeepLinesTogether
ParagraphFormatting.KeepLinesTogether
nopaneltrue

KeepWithNext

Excerpt Include
ParagraphFormatting.KeepWithNext
ParagraphFormatting.KeepWithNext
nopaneltrue

LineNumberingAllowed

Excerpt Include
ParagraphFormatting.LineNumberingAllowed
ParagraphFormatting.LineNumberingAllowed
nopaneltrue

LineSpacing

Excerpt Include
ParagraphFormatting.LineSpacing
ParagraphFormatting.LineSpacing
nopaneltrue

LineSpacingRule

Excerpt Include
ParagraphFormatting.LineSpacingRule
ParagraphFormatting.LineSpacingRule
nopaneltrue

PageBreakBefore

Excerpt Include
ParagraphFormatting.PageBreakBefore
ParagraphFormatting.PageBreakBefore
nopaneltrue

Shading

Excerpt Include
ParagraphFormatting.Shading
ParagraphFormatting.Shading
nopaneltrue

SpaceAfter

Excerpt Include
ParagraphFormatting.SpaceAfter
ParagraphFormatting.SpaceAfter
nopaneltrue

SpaceBefore

Excerpt Include
ParagraphFormatting.SpaceBefore
ParagraphFormatting.SpaceBefore
nopaneltrue

TextJustification

Excerpt Include
ParagraphFormatting.TextJustification
ParagraphFormatting.TextJustification
nopaneltrue

WidowControl

Excerpt Include
ParagraphFormatting.WidowControl
ParagraphFormatting.WidowControl
nopaneltrue
Methods

Name

Description

GetBorder(Border.Location)

Excerpt Include
ParagraphFormatting.GetBorder(Border.Location)
ParagraphFormatting.GetBorder(Border.Location)
nopaneltrue

GetIndent(ParagraphFormatting.IndentLocation)

Excerpt Include
ParagraphFormatting.GetIndent(ParagraphFormatting.IndentLocation)
ParagraphFormatting.GetIndent(ParagraphFormatting.IndentLocation)
nopaneltrue

SetIndent(Int32, ParagraphFormatting.IndentLocation)

Excerpt Include
ParagraphFormatting.SetIndent(Int32, ParagraphFormatting.IndentLocation)
ParagraphFormatting.SetIndent(Int32, ParagraphFormatting.IndentLocation)
nopaneltrue

SetLineSpacing(Int32, ParagraphFormatting.SpacingRule)

Excerpt Include
ParagraphFormatting.SetLineSpacing(Int32, ParagraphFormatting.SpacingRule)
ParagraphFormatting.SetLineSpacing(Int32, ParagraphFormatting.SpacingRule)
nopaneltrue
Classes

Name

Description

FontAlignment

Excerpt Include
ParagraphFormatting.FontAlignment
ParagraphFormatting.FontAlignment
nopaneltrue

IndentLocation

Excerpt Include
ParagraphFormatting.IndentLocation
ParagraphFormatting.IndentLocation
nopaneltrue

Justification

Excerpt Include
ParagraphFormatting.Justification
ParagraphFormatting.Justification
nopaneltrue

SpacingRule

Excerpt Include
ParagraphFormatting.SpacingRule
ParagraphFormatting.SpacingRule
nopaneltrue