欢迎来到天天文库
浏览记录
ID:1429534
大小:51.50 KB
页数:5页
时间:2017-11-11
《poi读取word转换html》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、POI读取word转换html文章分类:Java编程apachePOI读取word文档的文档比较少,所以只有自己慢慢的摸索,这篇文章也属于比较基础入门的,主要是针对读取word中的图片,以及文字的各种样式,如有不好的地方,请各位多多指教! Java代码 1./** 2. * 3. */ 4.package com.util; 5. 6.import java.io.BufferedWriter; 7.import java.io.File; 8.import java.io.FileInputStream; 9.import java.io.FileNot
2、FoundException; 10.import java.io.FileOutputStream; 11.import java.io.IOException; 12.import java.io.OutputStream; 13.import java.io.OutputStreamWriter; 14. 15.import org.apache.poi.hwpf.HWPFDocument; 16.import org.apache.poi.hwpf.model.PicturesTable; 17.import org.apache.poi.hwpf
3、.usermodel.CharacterRun; 18.import org.apache.poi.hwpf.usermodel.Picture; 19.import org.apache.poi.hwpf.usermodel.Range; 20. 21./** 22. * 23. * @author 张廷 下午10:36:40 24. * 25. */ 26.public class WordToHtml { 27. 28. /** 29. * 回车符ASCII码 30. */ 31. private static fin
4、al short ENTER_ASCII = 13; 32. 33. /** 34. * 空格符ASCII码 35. */ 36. private static final short SPACE_ASCII = 32; 37. 38. /** 1. * 水平制表符ASCII码 2. */ 3. private static final short TABULATION_ASCII = 9; 4. 5. private String htmlText = ""; 6. 7. /** 8
5、. * 读取每个文字样式 9. * 10. * @param fileName 11. * @throws Exception 12. */ 13. public void getWordAndStyle(String fileName) throws Exception { 14. 15. FileInputStream in = new FileInputStream(new File(fileName)); 16. 17. HWPFDocument doc = new HWPFDo
6、cument(in); 18. 19. // 取得文档中字符的总数 20. int length = doc.characterLength(); 21. 22. // 创建图片容器 23. PicturesTable pTable = doc.getPicturesTable(); 24. 25. htmlText = "
7、dy>"; 26. 27. // 创建临时字符串,好加以判断一串字符是否存在相同格式 28. 29. String tempString = ""; 30. 31. for (int i = 0; i < length - 1; i++) { 32. // 整篇文章的字符通过一个个字符的来判断,range为得到文档的范围 33. Range range = new Range(i, i + 1, doc); 34. 35.
此文档下载收益归作者所有