0

我希望我的 esri 插件查找并使用现有的 excel 实例。编码:

 Microsoft.Office.Interop.Excel.Application exApp = null;

   try

   {

      exApp =     (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");

   }

   catch (Exception err)

   {MessageBox.Show(err.ToString()); }

GetActiveObject 每次都会抛出异常,不管 excel 是否运行:异常 from marshal.getactiveobject

System.Runtime.InteropServices.COMException (0x800401E3); Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
at System.Runtime.InteropServices.Marshal.GetActiveObject( bla bla bla)

我写了一个小测试应用程序(Windows 应用程序)来做同样的事情,它按预期工作。如果 excel 正在运行,则返回对 excel 实例的引用,否则返回 null。它从不抛出异常。为什么插件每次都抛出异常?关于esri插件的东西?(这是arcmap的一个插件)

几天来一直在敲打这个,任何帮助表示赞赏。谢谢!

4

0 回答 0