There is:
Using java Syntax Highlighting
/**
* CLASS_TO_STYLE_ONLY: a Word style matching a class attribute will
* be used, and nothing else
*
* CLASS_PLUS_OTHER: a Word style matching a class attribute will
* be used; other css will be translated to direct formatting
*
* IGNORE_CLASS: css will be translated to direct formatting
*
*/
public enum FormattingOption
{
CLASS_TO_STYLE_ONLY, CLASS_PLUS_OTHER, IGNORE_CLASS
;
}
Parsed in 0.013 seconds, using
GeSHi 1.0.8.4
In XHTMLImporterImpl, there is setParagraphFormatting. The default is CLASS_PLUS_OTHER, but it sounds like you want
CLASS_TO_STYLE_ONLY (in which case you can disregard the below)
CLASS_PLUS_OTHERIf you were to use CLASS_PLUS_OTHER, it can be useful to have CSS on your HTML which matches your target docx. This prevents unwanted default CSS values having effect.
You can use HtmlCssHelper.createCssForStyles to generate that.
For the StyleTree arg, you can do:
StyleTree styleTree = wordMLPackage.getMainDocumentPart().getStyleTree();
Note that the styles which Word shows in its user interface aren't necessarily defined in the styles part of the docx. Typically, Word only writes an actual definition in the styles part if the style is actually being used in the document.
Of the styles which are actually defined, docx4j typically builds a StyleTree from that subset which are actually used somewhere in the document:
Using java Syntax Highlighting
/**
* Build a StyleTree for stylesInUse.
*
* @param stylesInUse styles actually in use in the main document part, headers/footers, footnotes/endnotes
* @param allStyles styles defined in the style definitions part
*/
public StyleTree
(Set
<String
> stylesInUse, Map
<String, Style
> allStyles
)
Parsed in 0.013 seconds, using
GeSHi 1.0.8.4
Your first step then is to ensure the styles your are interested in are actually defined in styles.xml.
After that, you could define a Set<String> stylesInUse which specifies all defined styles (ie the keys in Map<String, Style> allStyles) and use that to construct StyleTree.
For XHTML import purposes I guess it could be useful to add a constructor:
public StyleTree(Map<String, Style> allStyles)