我正在写一个自动化测试,以确定rtf文件是否被MS Word成功打开。到目前为止,我循环遍历给定目录中的所有rtfs并打开它们。稍后,我将不得不捕捉异常来生成报告(记录崩溃文字的文件名)。关闭微软Office C#控制台
我正在处理大量的文件。我的应用程序正在为每个文件打开一个新的Word实例。有人可以告诉我如何关闭Word吗?
public class LoadRTFDoc
{
private object FileName;
private object ReadOnly;
private object isVisible;
private object Missing;
private ApplicationClass WordApp;
private object Save;
private object OrigFormat;
private object RouteDoc;
public LoadRTFDoc(object filename)
{
this.WordApp = new ApplicationClass();
this.FileName = filename;
ReadOnly = false;
isVisible = true;
Missing = System.Reflection.Missing.Value;
Save = System.Reflection.Missing.Value;
OrigFormat = System.Reflection.Missing.Value;
RouteDoc = System.Reflection.Missing.Value;
}
public void OpenDocument()
{
WordApp.Visible = true;
WordApp.Documents.Open(ref FileName, ref Missing, ref ReadOnly, ref Missing, ref Missing,
ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
ref isVisible, ref Missing, ref Missing, ref Missing, ref Missing);
WordApp.Activate();
}
public void CloseDocument()
{
WordApp.Documents.Close(ref Save, ref OrigFormat, ref RouteDoc);
}
}
我在每个文档打开后都执行CloseDocument()方法。任何人都有这方面的见解?