jar包:
//fileName文件地址public static String convert2Html(String fileName, String outPutFile)
throws TransformerException, IOException,
ParserConfigurationException {
InputStream in = new FileInputStream(fileName);
XWPFDocument document = new XWPFDocument(in);
// 2) Prepare XHTML options (here we set the IURIResolver to
// load images from a "word/media" folder)
File imageFolderFile = new File("E:\\image");
XHTMLOptions options = XHTMLOptions.create().indent(4);
options.setExtractor(new FileImageExtractor(imageFolderFile));
options.setIgnoreStylesIfUnused(false);
options.setFragment(true);
// 3) Convert XWPFDocument to XHTML
File file = new File("e:\\现场验收.html");
OutputStream out = new FileOutputStream(file);
XHTMLConverter.getInstance().convert(document, out, options);
BufferedReader in1 = new BufferedReader(new FileReader("e:\\现场验收.html"));
String str;
StringBuffer strbf = new StringBuffer();
while ((str = in1.readLine()) != null)
{
System.out.println(str);
strbf.append(str);
}
in1.close();
// file.delete();
//返回html
return strbf.toString();
}