Applying Fonts
Using the Font class, you can apply text formatting to a CharacterRun or HTMLToWord object. To return a Font object use:
...
Code Block |
---|
|
NamedStyle heading1Style = doc.Styles[NamedStyle.BuiltIn.Heading1];
Font heading1Font = heading1Style.Font;
|
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.
...
Code Block |
---|
|
Paragraph para =
doc.InsertParagraphAfter(doc.Styles[NamedStyle.BuiltIn.BodyText]);
|
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.
...
Code Block |
---|
Document.CreateParagraphFormatting |
Returns a ParagraphFormatting object that represents the font used by the document's BodyText style.
Or Code Block |
---|
NamedStyle.ParagraphFormatting |
Returns a copy of the specified named style's paragraph formatting properties.//--- Return the paragraph formatting of the BodyText style. Code Block |
---|
|
WordApplication wwapp = new WordApplication();
Document doc = wwapp.Create();
ParagraphFormatting bodyTextFormatting = doc.CreateParagraphFormatting();
//--- Return a copy of the paragraph formatting of the BodyText2 Style.
WordApplication wwapp = new WordApplication();
Document doc = wwapp.Create();
ParagraphFormatting bodyText2Format =
doc.Styles[NamedStyle.BuiltIn.BodyText2].ParagraphFormatting;
|
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. Code Block |
---|
|
Paragraph para = doc.InsertParagraphAfter(doc.Styles[NamedStyle.BuiltIn.BodyText],
bodyTextFormatting);
|
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.
...