public boolean close()
{
String fileName = null;
if (this.doc != null)
{
try
{
fileName = Dispatch.get(this.doc, "Name").getString();
Dispatch.call(this.doc, "Close", new Variant(false));
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
this.doc = null;
}
}
System.out.println("关闭文件 " + fileName);
return true;
}
public boolean quit()
{
try
{
this.app.invoke("Quit", new Variant[] {});
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.println("退出word");
return true;
}
public boolean saveAs(String fileName) throws Exception
{
if (this.doc == null)
{
System.out.println("当前无文件");
return false;
}
else
{
Dispatch.call(this.doc, "SaveAs", fileName);
System.out.println("另存为" + fileName);
return true;
}
}
public boolean save() throws Exception
{
if (this.doc == null)
{
System.out.println("当前无文档,无法保存");
return false;
}
else
{
if (this.readOnly)
{
System.out.println("只读文档,保存失败");
return false;
}