麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > Java > 正文

Java實現將word轉換為html的方法示例【doc與docx格式】

2024-07-14 08:43:56
字體:
來源:轉載
供稿:網友

本文實例講述了html">Java實現將word轉換為html的方法。分享給大家供大家參考,具體如下:

 public static void main(String[] args) throws Exception { String filePath = "C:/Users/Administrator/Desktop/92個診療方案及臨床路徑/"; File file = new File(filePath); File[] files = file.listFiles(); String name = null; for (File file2 : files) {  Thread.sleep(500);  name = file2.getName().substring(0, file2.getName().lastIndexOf("."));  System.out.println(file2.getName());  if (file2.getName().endsWith(".docx") || file2.getName().endsWith(".DOCX")) {  CaseHtm.docx(filePath ,file2.getName(),name +".htm");  }else{  CaseHtm.dox(filePath ,file2.getName(),name +".htm");  }      } } /** * 轉換docx * @param filePath * @param fileName * @param htmlName * @throws Exception */ public static void docx(String filePath ,String fileName,String htmlName) throws Exception{ final String file = filePath + fileName; File f = new File(file);  // ) 加載word文檔生成 XWPFDocument對象 InputStream in = new FileInputStream(f); XWPFDocument document = new XWPFDocument(in); // ) 解析 XHTML配置 (這里設置IURIResolver來設置圖片存放的目錄) File imageFolderFile = new File(filePath); XHTMLOptions options = XHTMLOptions.create().URIResolver(new FileURIResolver(imageFolderFile)); options.setExtractor(new FileImageExtractor(imageFolderFile)); options.setIgnoreStylesIfUnused(false); options.setFragment(true); // ) 將 XWPFDocument轉換成XHTML OutputStream out = new FileOutputStream(new File(filePath + htmlName)); XHTMLConverter.getInstance().convert(document, out, options); } /** * 轉換doc * @param filePath * @param fileName * @param htmlName * @throws Exception */ public static void dox(String filePath ,String fileName,String htmlName) throws Exception{    final String file = filePath + fileName;    InputStream input = new FileInputStream(new File(file));    HWPFDocument wordDocument = new HWPFDocument(input);    WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());    //解析word文檔    wordToHtmlConverter.processDocument(wordDocument);    Document htmlDocument = wordToHtmlConverter.getDocument();    File htmlFile = new File(filePath + htmlName);    OutputStream outStream = new FileOutputStream(htmlFile);    DOMSource domSource = new DOMSource(htmlDocument);    StreamResult streamResult = new StreamResult(outStream);    TransformerFactory factory = TransformerFactory.newInstance();    Transformer serializer = factory.newTransformer();    serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");    serializer.setOutputProperty(OutputKeys.INDENT, "yes");    serializer.setOutputProperty(OutputKeys.METHOD, "html");    serializer.transform(domSource, streamResult);    outStream.close();  }
<dependency>  <groupId>fr.opensagres.xdocreport</groupId>  <artifactId>fr.opensagres.xdocreport.document</artifactId>  <version>1.0.5</version></dependency><dependency>   <groupId>fr.opensagres.xdocreport</groupId>   <artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId>   <version>1.0.5</version> </dependency>  <dependency>  <groupId>org.apache.poi</groupId>  <artifactId>poi</artifactId>  <version>3.12</version></dependency><dependency>  <groupId>org.apache.poi</groupId>  <artifactId>poi-scratchpad</artifactId>  <version>3.12</version></dependency>

 

希望本文所述對大家java程序設計有所幫助。


注:相關教程知識閱讀請移步到JAVA教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美性成人 | 99国产精品白浆在线观看免费 | 俄罗斯16一20sex牲色另类 | 久久另类视频 | bt 自拍 另类 综合 欧美 | 久久久久久久一区二区三区 | 激情综合婷婷久久 | 久久久一区二区三区精品 | 黄色的视频免费观看 | www.91sao| h视频在线播放 | 最新av在线免费观看 | 亚洲精品一区中文字幕 | 午夜视| 污视频在线免费 | av电影在线网站 | 国产免费让你躁在线视频 | 亚洲精品成人久久久 | 激情黄页 | 亚洲免费视频一区二区 | 在线看毛片的网站 | 黑人一级片视频 | 久久国产精品区 | 懂色粉嫩av久婷啪 | 精品国产一区二区三区久久久 | 欧美成人免费香蕉 | 国产女同疯狂激烈互摸 | 国产99久久精品一区二区300 | 欧美a视频在线观看 | 亚洲午夜视频在线 | 成年免费观看视频 | 在线观看国产网站 | 在线观看一二三 | 成人福利在线播放 | 欧产日产国产精品乱噜噜 | 美女喷水网站 | 亚洲字幕av| 免费一级特黄毛片 | 中国免费一级毛片 | 青青国产在线视频 | 精品国产一区二区三区四 |