Excel 2007从C#get_Value总是返回-2146826265 [英] Excel 2007 from C# get_Value always returns -2146826265
问题描述
我有一个引用Microsoft Excel 12.0对象库的小型C#应用程序。其中,它从Excel单元格读取一个值。它从一些较旧的Excel(.xls)文件和一些2007文件(.xlsx)中读取此值。该值对于所有.xls文件恢复正常,但我只获取.xlsx文件的以下值:-2146826265。
I have a small C# app that references the Microsoft Excel 12.0 Object Library. Among other things, it reads a value from an Excel cell. It reads this value from some older Excel (.xls) files and some 2007 files (.xlsx). The value comes back properly for all .xls files but I only get the following value for .xlsx files: -2146826265.
我正在阅读的单元格包含一个简单的公式:= A1 + B1。
The cell I'm reading contains a simple formula: "=A1+B1".
这是我使用的代码行
((Excel.Range)ws.Cells.get_Item(29, 17)).get_Value(null));
其中ws是当前的活动工作表。
Where ws is the current, active worksheet.
感谢您提供的任何帮助。
Thanks for any help you can offer.
推荐答案
get_value函数为其错误消息返回整数。
这是列表:
The get_value function returns integer for his error message. Here is the list :
-2146826281 = #Div/0!
-2146826246 - #N/A
-2146826259 = #Name?
-2146826288 = #Null!
-2146826252 = #Num!
-2146826265 = #Ref! <- yours !
-2146826273 = #Value!
这里是一篇非常好的文章:
And here is a very good article :
从这个非常好的答案:
How to know if a cell has an error in the formula in C#
这篇关于Excel 2007从C#get_Value总是返回-2146826265的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!