我正在使用Microsoft.Office.Interop.Word._Document
打开并使用c#.net代码更新word文档,每件事情都运行正常,但我无法确定Microsoft.Office.Interop.Word._Document
对象中可以提供状态的属性在某些代码执行点,天气结束是否关闭。
以下是我正在执行的示例代码,用于确定在文档打开时关闭文档。
public void UpdateSendDocument(string docPath)
{
bool docIsOpen = false;
Microsoft.Office.Interop.Word._Document wordDocumentBase = null;
Microsoft.Office.Interop.Word.Application officeWordApplication = null;
try
{
officeWordApplication = new Microsoft.Office.Interop.Word.Application();
wordDocumentBase = officeWordApplication.Documents.Open(docPath, Format: Microsoft.Office.Interop.Word.WdPasteOptions.wdKeepSourceFormatting);
docIsOpen = true;
// Update the document
// ApplyChanges(wordDocumentBase);
wordDocumentBase.Close();
docIsOpen = false;
// SendToNewParty(docPath);
}
finally
{
//here I wand to know the any property or method available in wordDocumentBase to check weather denouement is still open or not
if (wordDocumentBase != null && docIsOpen)
{
wordDocumentBase.Close(Type.Missing, Type.Missing, Type.Missing);
}
Marshal.ReleaseComObject(wordDocumentBase);
wordDocumentBase = null;
if (officeWordApplication != null)
{
officeWordApplication.Quit(Type.Missing, Type.Missing, Type.Missing);
Marshal.ReleaseComObject(officeWordApplication);
officeWordApplication = null;
}
}
}