实现页面预览word文档,用的是poi3.9,以下代码支持doc和docx。
/**
* word07版本(.docx)转html
* poi:word07在线预览
* */
public static void PoiWord07ToHtml (HttpServletRequest request) throws IOException{
String path= "C:\\Users\\Administrator\\Desktop\\";
String file = "C:\\Users\\Administrator\\Desktop\\word07.docx";
String file2 ="C:\\Users\\Administrator\\Desktop\\word07.html";
File f = new File(file);
if (!f.exists()) {
System.out.println("Sorry File does not Exists!");
} else {
if (f.getName().endsWith(".docx") || f.getName().endsWith(".DOCX")) {
//读取文档内容
InputStream in = new FileInputStream(f);
XWPFDocument document = new XWPFDocument(in);
File imageFolderFile = new File(path);