因为需求,公司在原先的项目上增加了几个功能。
有几点要求:
不能降版本,poi使用的是4.1.2版本,如果是3.1.5版本的poi可以跳过这篇文章,打开百度,输入java使用poi转换word。
不能付费,本着白嫖的原则,能不付费尽量不要付费,如果付费的话,推荐一下spire.doc这个功能还挺全的,代码也简单明了,这不是广告贴。
搜了很多文章,大多写的不是很全,更多的是poi3版本,写下这篇文章,希望可以解决所遇得问题之人的烦恼,快速提高效率,话不多说上代码
word07转html
/**
* docx格式转html
* @return
*/
public static void docxToHtml(String inFileName, String outFileName){
FileInputStream source = null;
OutputStream target = null;
try {
// 待转换文档输入流
source = new FileInputStream(new File(inFileName));
// 输出目标
target = new FileOutputStream(outFileName);
// 待转换的docx文档对象
XWPFDocument doc = new XWPFDocument(source);
// 转换成html
// 待转换的docx文档对象
XHTMLOptions optio