wordMLPackage.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert( htmlText, null,wordMLPackage) );
if i understand right htmlText is a string which contains the html code. I added docx4j-ImportXHTML-3.2.1.jar and i am using docx4j-3.2.1. The class XHTMLImporter is not recognized. Obviously i am doing something wrong.. but what?
I have found this code
- Code: Select all
String stringFromFile = FileUtils.readFileToString(new File(destFolder
+ "\\" + xhtmlFileName), "UTF-8");
WordprocessingMLPackage docxOut = WordprocessingMLPackage
.createPackage();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
docxOut.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(docxOut);
XHTMLImporter.setHyperlinkStyle("Hyperlink");
docxOut.getMainDocumentPart().getContent()
.addAll(XHTMLImporter.convert(stringFromFile, null));
docxOut.save(new java.io.File(destFolder + "\\" + docxFileName));
which is probably doing what i want, but i get a java.lang.NoClassDefFoundError: org/docx4j/org/xhtmlrenderer/layout/Styleable error. I have added Xalan-2.7.0.jar also and still getting the same error. Any help/hint would be appreciated.