Tag: running other programs

如何关闭Word文档的运行实例? (C#)

我可以看到很多非常相似的线程,但似乎没有什么能给我一个应该是非常基本的解决方案。 从我的winforms应用程序,我需要关闭word文档的运行实例(从应用程序本身打开)。 当我从应用程序中打开word文档时,我会在列表中跟踪它。 现在我该如何关闭同一个doc? 这是我尝试过的: private bool CloseWord(string osPath) //here I pass the fully qualified path of the file { try { Word.Application app = (Word.Application)Marshal.GetActiveObject(“Word.Application”); if (app == null) return true; foreach (Word.Document d in app.Documents) { if (d.FullName.ToLower() == osPath.ToLower()) { d.What? //How to close here? return true; } } return true; } […]