Message-ID: <1368303024.8509.1711648032238.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8508_1026355504.1711648032238" ------=_Part_8508_1026355504.1711648032238 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Table of Contents |
---|
=20
|
Paragraph Element.InsertParagraphAfter(NamedStyle style)= =20
Inserts an empty paragraph at the end of the specified Element. Th= is method applies the specified named style to the paragraph.
Paragraph Element.InsertParagraphAfter(NamedStyle style, Pa= ragraphFormatting props)=20
Inserts an empty paragraph at the end of the specified Element. Th= is method applies a specified named style and a set of formatting properties to the = paragraph. The formatting properties will override the style's properties= p>
Paragraph Element.InsertParagraphBefore(NamedStyle style)= =20
Inserts an empty paragraph at the beginning of the specified Eleme= nt. This method applies the specified named style to the paragraph.
Paragraph Element.InsertParagraphBefore(NamedStyle style, P= aragraphFormatting props)=20
Inserts an empty paragraph at the beginning of the specified Eleme= nt. This method applies a specified named style and a set of formatting properties t= o the paragraph. The formatting properties will override the style's proper= ties
Paragraph Position.InsertParagraph(NamedStyle style)=20
Inserts an empty paragraph at a specified position within an Eleme= nt. A Position object represents a cursor. This method applies the specifie= d named style= to the paragraph.
Before adding a paragraph to your file, you must create a content region= in which to insert the paragraph. Each editable region in a Word file is r= epresented by an Element object, or an object that extends Element, such as= a Document object.
WordApplication wordApp =3D new WordApplication(); Document doc =3D wordApp.Create();=20
To insert an empty paragraph, use one of the methods listed at the begin= ning of this section. All of the methods take a style argument, which speci= fies a named = style to apply to the inserted paragraph. The style argument may be nul= l. If it is null, the Normal style will be applied to the paragraph. The No= rmal style is the default style used by Microsoft Word. The following inser= ts an empty paragraph at the end of the document and applies the BodyText s= tyle to the paragraph:
Paragraph para =3D doc.InsertParagraphAfter(doc.Styles[NamedStyl= e.BuiltIn.BodyText]);=20
To add text to the paragraph, call one of the Element class's InsertText= After or InsertTextBefore methods. You can apply a font to the text by passing a Font= object to InsertTextAfter or InsertTextBefore. The following lines create = a Font object that we will use later when adding text to the paragraph:
Font paragraphFont =3D doc.CreateFont(); paragraphFont.FontName =3D "Times New Roman"; paragraphFont.FontSize =3D 10;=20
The method InsertTextAfter takes a string and inserts it at the end of t= he paragraph. The method's second parameter specifies a Font object (create= d above) to apply to the text.
para.InsertTextAfter("This document was created with Office= Writer for Word. It contains a single, left-justified paragraph.", paragraphFont);=20
The Paragraph class provides numerous formatting properties. The followi= ng left-justifies the paragraph:
//--- If para is a Paragraph object para.Formatting.TextJustification =3D ParagraphFormatting.Justification.Lef= t; //--- If myFormat is a ParagraphFormatting object myFormat.TextJustification =3D ParagraphFormatting.Justification.Left;=20
You can access existing paragraphs through the Element.Elements property= , for example:
//--- Open an existing Word file and get the first //--- paragraph. WordApplication wordApp =3D new WordApplication(); Document doc =3D wordApp.Open(@"C:\sample.doc"); Paragraph firstParagraph =3D (Paragraph)doc.GetElements(Element.Type.Paragr= aph)[0];=20
To apply a font to text in a paragraph, create a Font object and pass it= to Paragraph.InsertTextAfter or Paragraph.InsertTextBefore, as demonstrate= d above.
Other paragraph formatting can be applied through the Paragraph object o= r the ParagraphFormatting object. To create a ParagraphFormatting object, c= all Document.CreateParagraphFormatting:
WordApplication wordApp =3D new WordApplication(); Document doc =3D wordApp.Create(); ParagraphFormatting bodyTextFormatting =3D doc.CreateParagraphFormatting();=20
Next, set ParagraphFormatting properties.
//--- Set the amount of whitespace that should be //--- placed above a paragraph in twips (1/1440 in). bodyTextFormatting.SpaceBefore =3D 240; //--- Display line numbers. bodyTextFormatting.LineNumberingAllowed =3D true;=20
To assign the ParagraphFormatting object that you created to a paragraph= , pass it to Element.InsertParagraphAfter or Element.InsertParagraphBefore = when you create a new paragraph.
Paragraph para =3D doc.InsertParagraphAfter(doc.Styles[NamedStyl= e.BuiltIn.BodyText], bodyTextFormatting);=20