1.用JCOB1.9做的
2.源码如下
public class FileConversion {
private static ActiveXComponent axp;
private static Dispatch dphAll;
private static Dispatch dph;
/**
* 将Word转化为html
* @param comFile
* @param toFile
*/
public static void wordToHtml(String comFile,String toFile)
{
axp = new ActiveXComponent("Word.Application");//启动word
try {
dphAll = (Dispatch) axp.getProperty("Documents").toDispatch();
dph = (Dispatch) Dispatch.invoke(dphAll,"Open", Dispatch.Method,
new Object[]{comFile,new Variant(false), new Variant(true)},
new int[1]).toDispatch();//打开word文件
axp.setProperty("Visible", new Variant(false));//设置word不可见
Dispatch.invoke(dph,"SaveAs", Dispatch.Method, new Object[]{toFile,new Variant(8)}, new int[1]);//作为html格式保存
Dispatch.call((Dispatch) dph, "Close", new Variant(false));
} catch (Exception e)
{
e.printStackTrace();
}
finally
{
axp.invoke("Quit", new Variant[] {});
}
}
}