This project has moved and is read-only. For the latest updates, please go here.

Css Class into Word Style

Jul 25, 2012 at 3:58 PM
Edited Jul 25, 2012 at 3:59 PM


I don't know if this is possible, but I would like to be able to put a Word style onto an element based on the css class name of an HTML element.


Say I have the following HTML:

<table class="MyClass">

This would add the relevant OpenXml to the document:

<w:tblStyle w:val="MyClass" />

Then I can define "MyClass" in my template and the style will be picked up.

Is this posible?

Feb 14, 2013 at 9:45 AM

Were you able to do this?
Feb 14, 2013 at 10:09 AM
Unfortunately no.
Feb 14, 2013 at 10:16 AM
Edited Feb 14, 2013 at 10:17 AM
But do you know if it is possible to achieve it? I am trying to convert HTML to docx where the style is in referenced css file. The docx file is generating without any style at present.
Feb 14, 2013 at 10:18 AM
I don't know if it is possible - I would try and contact the developer of the component.
Feb 14, 2013 at 10:31 AM

unfortunalety, CSS file are not handled - far way too complicated.
However, as Paul suggest it, you can define some class attribute in your HTML and let the converter pick up the matching OpenXml style name.
But this only work if you provide your own Word template (so HtmlToOpenXml will check for the given style name).
byte[] data = Demo.Properties.Resources.template;
generatedDocument.Write(data, 0, data.Length);
generatedDocument.Position = 0L;
using (WordprocessingDocument package = WordprocessingDocument.Open(generatedDocument, true))
  • btw : use the latest source code, not the released version. Sorry still not got time to finish
Feb 14, 2013 at 11:26 AM
Edited Feb 14, 2013 at 11:32 AM
I see that, there are few components which will inline the styles from css. I will try that out before passing the HTML to HtmlConverter.