0

I'm looking for a clean way to output errors in C# when using Excel with interop.

When the file is not "right" a have a message like "blabla HRESULT: 0x800AC472".

I'd rather want a message like "The file used has this or that problem". In order to do that I would need to know to what error does each HRESULT map to ?

How to get such a list of errors ?

I've look at MSDN, found some description, but I can't seem to find the list of all codes like the "0x800AC472" mention above.

4

1 回答 1

3

我有 Excel HRESULT 代码 0x800AC472 as VBA_E_IGNORE,这表明 Excel 已“暂停对象浏览器”。

在某些情况下,Excel 将拒绝所有传入的 COM 请求。发生这种情况的两种情况是用户

  • 正忙于编辑公式,或
  • 在 Excel 工作表上按下鼠标按钮。

可能还有其他情况 - 例如,当 Excel 忙于计算时,我不确定错误代码是什么。

如果您正在执行 COM 自动化以与交互使用的 Excel 实例通信,那么您对 ​​Excel 进行的任何 COM 调用都可能返回此错误。我对Excel-DNA采用的一种方法(互操作总是从 Excel 进程中的加载项发生)是尝试调用 Application.Run(...) 以在加载项中运行宏。Application.Run 调用成功后,宏将在 Excel 主线程上运行,在该上下文中 COM 请求不会因 Excel 暂停 COM 调用而失败。

您可以从 Excel 中获得的其他一些 COM 错误是:

    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.
于 2014-06-05T22:23:45.863 回答