Skip to end of metadata
Go to start of metadata

Description

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.

C#
vb.net

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.

Examples

C#
vb.net

Properties

Name

Description

AbsolutePositioning

Returns an AbsolutePositioning object on which you can control the absolute positioning for a paragraph.

AfterAutoSpacing

Sets or returns a boolean that represents if Word will automatically handle spacing below a paragraph.

AllowAutoHyphenation

Sets or returns a boolean representing if auto hyphening is allowed for a paragraph.

BeforeAutoSpacing

Sets or returns a boolean that represents if Word will automatically handle spacing above a paragraph.

KeepLinesTogether

Sets or returns a boolean that represents if Word attempts to keep all lines of a paragraph on the same page. (It prevents a page break within a paragraph.)

KeepWithNext

Sets or returns a boolean that represents if Word attempts to keep a paragraph on the same page as the next paragraph. (It prevents a page break a paragraph and the next paragraph.)

LineNumberingAllowed

Sets or returns a boolean that represents if Word will display line numbers next to a paragraph. This property has no effect in documents or sections with no line numbers.

LineSpacing

Returns an int representing the line spacing for a paragraph.

LineSpacingRule

Returns a ParagraphFormatting.LineSpacingRule object that represents the type of line spacing for a paragraph. There are 3 types: AtLeast, Exactly, and Multiple. AtLeast and Exactly use twips to specify a minimum height and exact height respectively. One twip = (1/20 pt) or (1/1440 in). Multiple specifies a spacing as a number of lines. Multiple is the most common type of spacing.

PageBreakBefore

Sets or returns a boolean that represents if Word will have a paragraph be the start of a new page. (It inserts a manual page break before the paragraph.)

Shading

Returns a Shading object which on which you can manipulate the shading (fill color and/or pattern) properties of a paragraph.

SpaceAfter

Sets or returns an int representing the amount of whitespace that should be placed below a paragraph in twips. One twip = (1/20 pt) or (1/1440 in)

SpaceBefore

Sets or returns an int representing the amount of whitespace that should be placed above a paragraph in twips. One twip = (1/20 pt) or (1/1440 in)

TextJustification

Sets or returns a ParagraphFormatting.Justification object that represents the text justification for a paragraph.

WidowControl

Sets or returns a boolean representing if Word will use Widow Control for a paragraph. When set to true, Word will not print the last line of a paragraph by itself at the top of a page (widow) or the first line of a paragraph by itself at the bottom of a page (orphan).

Methods

Name

Description

GetBorder(Border.Location)

Returns a Border object on which you can manipulate the border properties of a paragraph for a specified location. Valid Border locations are: Top, Left, Bottom, Right, Between, and Bar. Bar and Between are less obvious locations and they are explained below.

GetIndent(ParagraphFormatting.IndentLocation)

Returns an int representing the indent of the paragraph in twips.

SetIndent(Int32, ParagraphFormatting.IndentLocation)

Sets an int representing the indent of the paragraph in twips.

SetLineSpacing(Int32, ParagraphFormatting.SpacingRule)

Sets an int representing the line spacing for a paragraph.

Nested Classes

Name

Description

FontAlignment

The page ParagraphFormatting.FontAlignment does not exist.

IndentLocation

Indent locations for a paragraph.

Justification

Justification types for a paragraph.

SpacingRule

Line spacing types for a paragraph. If the line spacing is not at least the height of the font used on the line then the top of the character string is truncated.
  • No labels