一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

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

服務(wù)器之家 - 編程語言 - Java教程 - Java實(shí)現(xiàn)將word轉(zhuǎn)換為html的方法示例【doc與docx格式】

Java實(shí)現(xiàn)將word轉(zhuǎn)換為html的方法示例【doc與docx格式】

2021-07-19 09:11只為學(xué)習(xí)與記錄 Java教程

這篇文章主要介紹了Java實(shí)現(xiàn)將word轉(zhuǎn)換為html的方法,結(jié)合實(shí)例形式分析了java針對(duì)doc與docx格式文件的相關(guān)轉(zhuǎn)換操作技巧,需要的朋友可以參考下

本文實(shí)例講述了java實(shí)現(xiàn)將word轉(zhuǎn)換為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個(gè)診療方案及臨床路徑/";
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");
 }
 
   }
}
/**
* 轉(zhuǎn)換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對(duì)象
inputstream in = new fileinputstream(f);
xwpfdocument document = new xwpfdocument(in);
// ) 解析 xhtml配置 (這里設(shè)置iuriresolver來設(shè)置圖片存放的目錄)
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轉(zhuǎn)換成xhtml
outputstream out = new fileoutputstream(new file(filepath + htmlname));
xhtmlconverter.getinstance().convert(document, out, options);
}
/**
* 轉(zhuǎn)換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>

希望本文所述對(duì)大家java程序設(shè)計(jì)有所幫助。

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本午夜色 | 91久久青青草原线免费 | 国产成人精品午夜在线播放 | 久热这里只有精品99国产6 | 男女发生性关系视频 | 久久亚洲网站 | 美女操穴视频 | 日韩免费观看成第15集 | 欧美一区二区三区不卡视频 | 被巨大黑人的翻白眼 | www一级片 | 精品美女国产互换人妻 | 国产精品女主播自在线拍 | 91av爱爱| 成人在线小视频 | 91精品天美精东蜜桃传媒免费 | 免费岛国片 | 被夫上司侵犯了中文字幕 | 国产v在线在线观看羞羞答答 | 午夜精品区 | 男人猛戳女人下部30分钟 | 97se亚洲国产综合自在线观看 | 69热精品视频在线看影院 | 日韩在线视频二区 | chinese老太granny chinese国产人妖hd | 美女尿口羞羞视频 | 国产亚洲精品一区二区在线播放 | 性伴交换多p | 4455永久在线观免费看片 | 日剧整部剧护妻狂魔免费观看全集 | porno xxxx日本| 欧美亚洲国产精品久久第一页 | 毛片资源站 | 91在线 一区 二区三区 | 西西人体大胆啪啪私拍色约约 | 给我免费观看的视频在线播放 | 色网在线视频 | 亚洲精品卡一卡2卡3卡4卡 | 22sihu国产精品视频影视资讯 | 日韩欧美一区黑人vs日本人 | 天堂男人在线 |