Forums     Knowledge Base     OfficeWriter Online     
 
 
This documentation is for
OfficeWriter v3.8.1
.NET Platform

View Docs for Another
Version or Platform

Programmer's Reference > WordApplication API > ParagraphFormatting

The ParagraphFormatting Object


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.

There are two ways to obtain an instance of this class: Create a new normal paragraph formatting object using Document.CreateParagraphFormatting(). This will return a copy of a particular style's paragraph formatting. 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:

[csharp]
// 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, bodyText2Formatting);

// Get paragraph formatting from BodyText2 Style
WordApplication app = new WordApplication();
Document doc = app.Create();
ParagraphFormatting bodyText2Formatting = doc.Styles[NamedStyle.BuiltIn.BodyText2];
// Set some properties
bodyText2Formatting.PageBreakBefore = true;
bodyText2Formatting.TextJustification = ParagraphFormatting.Justification.Right;
// Apply it to a new paragraph
doc.InsertParagraphAfter(null, bodyText2Formatting);
[vbnet]
' Get BodyText paragraph formatting from Document
Dim app As WordApplication = new WordApplication()
Dim doc As Document = app.Create()
Dim bodyTextFormatting = doc.CreateParagraphFormatting()
' Set some properties
bodyTextFormatting.PageBreakBefore = True
bodyTextFormatting.TextJustification = ParagraphFormatting.Justification.Right
' Apply it to a new paragraph
doc.InsertParagraphAfter(Nothing, bodyText2Formatting)

' Get paragraph formatting from BodyText2 Style
Dim app As WordApplication = new WordApplication()
Dim doc As Document = app.Create()
Dim bodyText2Formatting As ParagraphFormatting = doc.Styles(NamedStyle.BuiltIn.BodyText2)
' Set some properties
bodyText2Formatting.PageBreakBefore = True
bodyText2Formatting.TextJustification = ParagraphFormatting.Justification.Right
' Apply it to a new paragraph
doc.InsertParagraphAfter(Nothing, bodyText2Formatting)


ParagraphFormatting Enumerations

NameDescription
ParagraphFormatting.FontAlignment

Font alignments for a paragraph

ParagraphFormatting.IndentLocation

Indent locations for a paragraph

ParagraphFormatting.Justification

Justification types for a paragraph

ParagraphFormatting.SpacingRule

Line spacing types for a paragraph



ParagraphFormatting Properties

Property Type Access Description
AbsolutePositioning AbsolutePositioning read

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

AfterAutoSpacing boolean read
write

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

AllowAutoHyphenation boolean read
write

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

BeforeAutoSpacing boolean read
write

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

Border Border read

Returns an Border object on which you can manipulate the border properties of a paragraph for a specified location

Indent int read
write

Sets or returns the indent in twips for a specified location

KeepLinesTogether boolean read
write

Sets or returns a boolean that represents if Word attempts to keep all lines of a paragraph on the same page

KeepWithNext boolean read
write

Sets or returns a boolean that represents if Word attempts to keep a paragraph on the same page as the next paragraph

LineNumberingAllowed boolean read
write

Sets or returns a boolean that represents if Word will display line numbers next to a paragraph

LineSpacing int read
write

Sets or returns an int representing the line spacing for a paragraph

LineSpacingRule ParagraphFormatting.SpacingRule read

Returns a ParagraphFormatting.LineSpacingRul object that represents the type of line spacing for a paragraph

PageBreakBefore boolean read
write

Sets or returns a boolean that represents if Word will have a paragraph be the start of a new page

Shading Shading read

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

SpaceAfter int read
write

Sets or returns an int representing the amount of whitespace that should be placed below a paragraph in twips

SpaceBefore int read
write

Sets or returns an int representing the amount of whitespace that should be placed above a paragraph in twips

TextJustification ParagraphFormatting.Justification read
write

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

WidowControl boolean read
write

Sets or returns a boolean representing if Word will use Widow Control for a paragraph



This object does not have any methods defined.



Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.