C# C中Excel互操作中的HRESULT代码#
我正在寻找一种干净的方法,在使用Excel和interop时用C#输出错误 当文件不“正确”时,将显示类似“blabla HRESULT:0x800AC472”的消息 我更希望看到这样的消息:“使用的文件有这个或那个问题”。为了做到这一点,我需要知道每个HRESULT映射到什么错误 如何获得这样的错误列表C# C中Excel互操作中的HRESULT代码#,c#,excel,error-handling,interop,hresult,C#,Excel,Error Handling,Interop,Hresult,我正在寻找一种干净的方法,在使用Excel和interop时用C#输出错误 当文件不“正确”时,将显示类似“blabla HRESULT:0x800AC472”的消息 我更希望看到这样的消息:“使用的文件有这个或那个问题”。为了做到这一点,我需要知道每个HRESULT映射到什么错误 如何获得这样的错误列表 我查看了MSDN,找到了一些描述,但似乎找不到上面提到的“0x800AC472”之类的所有代码的列表。我有Excel HRESULT代码0x800AC472作为VBA_E_IGNORE,这表明
我查看了MSDN,找到了一些描述,但似乎找不到上面提到的“0x800AC472”之类的所有代码的列表。我有Excel HRESULT代码0x800AC472作为
VBA_E_IGNORE
,这表明Excel已“暂停对象浏览器”
在某些情况下,Excel将拒绝所有传入的COM请求。发生这种情况的两种情况是用户
- 正在忙于编辑公式,或
- 在Excel工作表上按下鼠标按钮
const uint RPC_E_SERVERCALL_RETRYLATER = 0x8001010A;
const uint RPC_E_CALL_REJECTED = 0x80010001; // Not sure when we get this one?
// Maybe when trying to get the Application object from another thread,
// triggered by a ribbon handler, while Excel is editing a cell.
const uint VBA_E_IGNORE = 0x800AC472; // Excel has suspended the object browser
const uint NAME_NOT_FOUND = 0x800A03EC; // When called from the main thread, but Excel is busy anyway.
我将Excel HRESULT代码0x800AC472设置为
VBA\u E\u IGNORE
,这表示Excel已“挂起对象浏览器”
在某些情况下,Excel将拒绝所有传入的COM请求。发生这种情况的两种情况是用户
- 正在忙于编辑公式,或
- 在Excel工作表上按下鼠标按钮
const uint RPC_E_SERVERCALL_RETRYLATER = 0x8001010A;
const uint RPC_E_CALL_REJECTED = 0x80010001; // Not sure when we get this one?
// Maybe when trying to get the Application object from another thread,
// triggered by a ribbon handler, while Excel is editing a cell.
const uint VBA_E_IGNORE = 0x800AC472; // Excel has suspended the object browser
const uint NAME_NOT_FOUND = 0x800A03EC; // When called from the main thread, but Excel is busy anyway.
我将Excel HRESULT代码0x800AC472设置为
VBA\u E\u IGNORE
,这表示Excel已“挂起对象浏览器”
在某些情况下,Excel将拒绝所有传入的COM请求。发生这种情况的两种情况是用户
- 正在忙于编辑公式,或
- 在Excel工作表上按下鼠标按钮
const uint RPC_E_SERVERCALL_RETRYLATER = 0x8001010A;
const uint RPC_E_CALL_REJECTED = 0x80010001; // Not sure when we get this one?
// Maybe when trying to get the Application object from another thread,
// triggered by a ribbon handler, while Excel is editing a cell.
const uint VBA_E_IGNORE = 0x800AC472; // Excel has suspended the object browser
const uint NAME_NOT_FOUND = 0x800A03EC; // When called from the main thread, but Excel is busy anyway.
我将Excel HRESULT代码0x800AC472设置为
VBA\u E\u IGNORE
,这表示Excel已“挂起对象浏览器”
在某些情况下,Excel将拒绝所有传入的COM请求。发生这种情况的两种情况是用户
- 正在忙于编辑公式,或
- 在Excel工作表上按下鼠标按钮
const uint RPC_E_SERVERCALL_RETRYLATER = 0x8001010A;
const uint RPC_E_CALL_REJECTED = 0x80010001; // Not sure when we get this one?
// Maybe when trying to get the Application object from another thread,
// triggered by a ribbon handler, while Excel is editing a cell.
const uint VBA_E_IGNORE = 0x800AC472; // Excel has suspended the object browser
const uint NAME_NOT_FOUND = 0x800A03EC; // When called from the main thread, but Excel is busy anyway.
像这样的?您似乎还可以创建自定义代码,因此如果它不存在,可能在代码中的其他地方定义了它:您是否有特定的代码来发布错误发生的位置?以0x800A开头的HRESULT代码是与您进行互操作的应用程序中的内部错误。最后4位是内部错误的十六进制代码。在您的例子中,这是0xC472==“Excel错误50290”。这会给你的用户带来十万次谷歌点击。“使用的文件有这样或那样的问题”不会给你的用户谷歌点击,微软没有维护内部错误代码到错误描述的映射,谷歌也没有维护你的错误描述列表。使用Marshal.GetHRForException()不,我没有代码示例抱歉,它只是发生在有人运行我的工具时,而我似乎无法复制它。这就是我想创建更好的错误消息的原因像这样的方法?您似乎还可以创建自定义代码,因此如果它不存在,可能在代码中的其他地方定义了它:您是否有特定的代码来发布错误发生的位置?以0x800A开头的HRESULT代码是与您进行互操作的应用程序中的内部错误。