This project has moved. For the latest updates, please go here.

Default style

You can assign a style for all the paragraphs meet during the conversion. Of course, the style attributes on the tag are still applied over the specified default style.

In this example, the Intense Quote style is used.

converter.HtmlStyles.DefaultStyle = converter.HtmlStyles.GetStyle("Intense Quote");

<h1>A title</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Duis dictum leo quis ipsum tempor nec ultrices sapien elementum.

Predefined Style

When the converter encounters some tags (as <a> and <h1>) and the styles are missing from the Word document, the text is displayed in raw format, which doesn't give a nice visual feedback.
To circumvent this behavior, the converter will automatically insert the styles if needed.
  • Caption
  • Heading 1 to 6
  • HyperLink

CSS Class

If you wish to apply a specific style on an Html tag, you can use the native "class" attribute.
Each time the converter encounters the "class" attribute, it looks for a Style in the Word document with the same name (case insensitive).

<table class="Standard_Table TableWhite" cellspacing="0" cellpadding="0">
    <td>Column 1</td>
    <td>Column 2</td>
In this sample, the converter will try to find a style with the name Standard_Table and if not found, TableWhite.

Some texts does not apply the expected style

If you add this line of code in the startup example and run it again, you will not see the "Heading 1" style applied.
 <h1>First steps</h1>
In fact, the "Heading 1" style is well applied but this style does not exists in the document ; when you create a new document, no styles are defined : it's up to you. HtmlToOpenXml handles automatically the hyperlink style for you but it does not deals with any others.
You can subscribe to the StyleMissing event to be warned and add them yourself.

converter.HtmlStyles.StyleMissing += delegate(object sender, StyleEventArgs e)

Generally, you will load in memory an existing document template and append the Html conversion inside it. MS Word 2007 embeds a lot of informations (like styles, themes, document properties, ...) that you don't really want to bother with.

Last edited May 22, 2014 at 4:49 PM by onizet, version 9