Skip to end of metadata
Go to start of metadata

Table of Contents

This article covers applying fonts, named styles, paragraph formatting and table formatting.

 

Applying Fonts

Using the Font class, you can apply text formatting to a CharacterRun or HTMLToWord object. To return a Font object use:

Returns a Font object that represents the font used by the document's Normal style.

Or

Returns a copy of the specified named style's font.

To define a font and apply it to a paragraph, first create a Font object:

Add an empty paragraph to your document:

To add text to the paragraph call one of the Element class's InsertTextAfter or InsertTextBefore methods. Pass the the text to add and your Font object to the method:

To get a copy of a built-in style's font, use the NamedStyle.Font property.

Named Styles

The Styles collection contains all the named styles in the Word document. All Word documents contain a set of built-in styles. These are included in the Styles collection. If you use WordWriter to open an existing Word file, it may also contain custom named styles which will be added to the Styles collection.

You cannot create or modify a named style with WordWriter.

To return a document's Styles collection, use the property Document.Styles:

To apply a style to a paragraph, pass it to InsertParagraphAfter or InsertParagraphBefore when you add the paragraph to your document:

Paragraph Formatting

When you add a paragraph to a document using Element.InsertParagraphAfter or Element.InsertParagraphBefore, you can pass a ParagraphFormatting object to the method. A ParagraphFormatting object contains a set of formatting properties that can be applied to a paragraph.

To return a ParagraphFormatting object, use:

  • Returns a ParagraphFormatting object that represents the font used by the document's BodyText style.
    Or

  • Returns a copy of the specified named style's paragraph formatting properties.//--- Return the paragraph formatting of the BodyText style.

    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.

Table Formatting

To apply a font to text in a table cell, create a Font object and pass it to TableCell.InsertTextAfter or TableCell.InsertTextBefore, as demonstrated above.

Other paragraph formatting can be applied through the Table object or the TableFormatting object. To create a TableFormatting object, call Document.CreateTableFormatting:

Next, set TableFormatting properties.

To assign the TableFormatting object that you created to a table, pass it to Element.InsertTableAfter or Element.InsertTableBefore when you create a new table.

  • No labels