参考资源:http://www.iteye.com/topic/356374
public void WordToHtml(String filename, String savefilename)
{
ActiveXComponent app = new ActiveXComponent("Word.Application");// 启动word
try
{
app.setProperty("Visible", new Variant(false));
// 设置word不可见
Object docs = app.getProperty("Documents").toDispatch();
Object doc = Dispatch.invoke((Dispatch)docs, "Open", Dispatch.Method, new Object[] { filename, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
// 打开word文件
Dispatch.invoke((Dispatch)doc, "SaveAs", Dispatch.Method, new Object[]{ savefilename, new Variant(8) }, new int[1]);
// 作为html格式保存到临时文件
Dispatch.call((Dispatch)doc, "Close", new Variant(false));
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[]{});
app = null;
}
}
public void WordToHtml(String filename, String savefilename)
{
ActiveXComponent app = new ActiveXComponent("Word.Application");// 启动word
try
{
app.setProperty("Visible", new Variant(false));
// 设置word不可见
Object docs = app.getProperty("Documents").toDispatch();
Object doc = Dispatch.invoke((Dispatch)docs, "Open", Dispatch.Method, new Object[] { filename, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
// 打开word文件
Dispatch.invoke((Dispatch)doc, "SaveAs", Dispatch.Method, new Object[]{ savefilename, new Variant(8) }, new int[1]);
// 作为html格式保存到临时文件
Dispatch.call((Dispatch)doc, "Close", new Variant(false));
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[]{});
app = null;
}
}