【问题标题】:Excel 2007 from C# get_Value always returns -2146826265来自 C# get_Value 的 Excel 2007 始终返回 -2146826265
【发布时间】:2011-05-09 04:31:15
【问题描述】:

我有一个引用 Microsoft Excel 12.0 对象库的小型 C# 应用程序。除其他外,它从 Excel 单元格中读取一个值。它从一些较旧的 Excel (.xls) 文件和一些 2007 文件 (.xlsx) 中读取此值。所有 .xls 文件的值都正确返回,但我只得到 .xlsx 文件的以下值:-2146826265。

我正在阅读的单元格包含一个简单的公式:“=A1+B1”。

这是我正在使用的代码行

((Excel.Range)ws.Cells.get_Item(29, 17)).get_Value(null));

其中 ws 是当前的活动工作表。

感谢您提供的任何帮助。

【问题讨论】:

  • -2146826265 看起来很像错误代码。将其重新表示为无符号十六进制常量,并在 C# 或 Excel 的上下文中搜索它。

标签: c# excel vba excel-2007


【解决方案1】:

get_value 函数为他的错误消息返回整数。 这是列表:

-2146826281 = #Div/0!
-2146826246 - #N/A
-2146826259 = #Name?
-2146826288 = #Null!
-2146826252 = #Num!
-2146826265 = #Ref!     <- yours !
-2146826273 = #Value!

这是一篇非常好的文章:

http://xldennis.wordpress.com/2006/11/22/dealing-with-cverr-values-in-net-%E2%80%93-part-i-the-problem/

从这个非常好的答案:

How to know if a cell has an error in the formula in C#

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-27
    • 2014-06-21
    • 2020-02-23
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    相关资源
    最近更新 更多