Tag: office automation

仅在尝试使用Word DocumentClass时在prod中获取对象引用错误

我正在编写一个使用.dotx模板的程序,并在aspx页面中进行数据合并。 该程序在我的开发工作站本地工作完美,但当我将它部署到测试IIS服务器时,它在下面的第二行失败,给我一个对象参考错误。 我之前遇到问题,因为Word Com对象不在IIS服务器上,因此我将Word加载到服务器上并在DCom中设置权限并解决了该问题。 但现在我在以wRange = …..开头的行上出现此错误 正如我所说,该程序在调试模式下完美地工作。 有任何想法吗? Microsoft.Office.Interop.Word.DocumentClass System.NullReferenceException: Object reference not set to an instance of an object 代码行: Document BaseDocument = oWord.Documents.Open(ref oTemplate, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, […]

如何关闭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; } […]