用java将Word文档转Html
boolean flag = false;
try
{
app.setProperty("Visible", new Variant(false));
//设置word不可见
Object docs = app.getProperty("Documents").toDispatch();
Object doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{inFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch();
//打开word文件
Dispatch.invoke(doc,"SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]);
//作为html格式保存到临时文件
Variant f = new Variant(false);
Dispatch.call(doc, "Close", f);
flag = true;
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
System.out.println("转化完毕!");
}
}
else
{
System.out.print("Folder");
pathss = paths;
//进入下一级目录
pathss = pathss + lists[i].getName() + "\\";
//递归遍历所有目录
change(pathss, savepaths);
}
}
}
//------------------------------------------------------------------------------
//方法原型: main(String[] args)
//功能描述: main文件
//输入参数: 无
//输出参数: 无
//返 回 值: 无
//其它说明: 无
//------------------------------------------------------------------------------
public static void main(String[] args)
{
String paths = new String("E:\\Project\\");
String savepaths = new String ("D:\\javapro\\");
change(paths,savepaths);
}
}
联系客服