java 解析word2007带有word中的基本格式


通过解析word反转成html文件再解析html文件的形式获取带有格式的word文本:

依赖包: http://download.csdn.net/detail/sxg0205/8959545

注意点:实测发现只能带有word的基本格式如左对齐、右对齐、换行等,插入的图片、横线等格式貌似无法获取,可能是写的不全的原因吧,后续再定位;


代码:

public void canExtractImage(String path, String name) throws IOException {


InputStream is = new FileInputStream("d:\\excel\\doc\\1.docx");
XWPFDocument document = new XWPFDocument(is);


XHTMLOptions options = XHTMLOptions.create();// .indent( 4 );
// Extract image
File imageFolder = new File("d:/excel/test.html");
options.setExtractor(new FileImageExtractor(imageFolder));
// URI resolver
options.URIResolver(new FileURIResolver(imageFolder));


OutputStream out = new FileOutputStream(new File("d:/excel/test.html"));
XHTMLConverter.getInstance().convert(document, out, options);




InputStream i1s = new FileInputStream("d:/excel/test.html");

java.io.BufferedReader in = null;
StringBuffer sb = new StringBuffer();
try {
in = new java.io.BufferedReader(new java.io.InputStreamReader(i1s));

for (String line; (line = in.readLine()) != null;) {
sb.append(line);
}
} finally {
if (in != null) {
in.close();
}
}

syso(sb.toString());
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值