国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Java實現將word轉換為html的方法示例【doc與docx格式】

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

2021-07-19 09:11只為學習與記錄 Java教程

這篇文章主要介紹了Java實現將word轉換為html的方法,結合實例形式分析了java針對doc與docx格式文件的相關轉換操作技巧,需要的朋友可以參考下

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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();
 }
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<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程序設計有所幫助。

原文鏈接:https://blog.csdn.net/tangyaliang11/article/details/79007873

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩av在线中文字幕 | 午夜av免费 | 天天精品视频免费观看 | 影音先锋在线看片资源 | 91网站免费 | 久久国产精品视频 | 欧美一区二区久久 | 日韩精品影院 | 久久久久亚洲美女啪啪 | 蜜桃一二三区 | 久久在线视频 | 天天操网 | 国产精品成人国产乱一区 | jav久久亚洲欧美精品 | 一区二区三区免费在线观看 | 久久久91 | 亚洲激情一区 | 欧洲精品久久久久69精品 | 精品日韩一区二区 | 久久极品 | 日韩精品在线视频 | 高清国产一区二区三区 | 91精品国产一区二区 | jizzzz中国| 国产精品网站在线观看 | 日韩中文字幕一区 | 亚洲91| 国产精品久久久久久婷婷天堂 | 国产综合亚洲精品一区二 | 久久综合久久88 | 综州合另类| 日韩国产一区二区 | 久久久国产精品久久久 | 国产精品国产三级国产aⅴ 成人在线免费看 | 伊人网在线视频观看 | 久久国产精品久久喷水 | 黄视频网站免费观看 | 国产精品久久久久久亚洲调教 | 成人午夜网站 | eeuss国产一区二区三区四区 | 91久久久久久久久久久久久久久久 |