Excel对象上的错误:对象引用未设置为对象的实例. [英] Error on Excel object: Object reference not set to an instance of an object.
本文介绍了Excel对象上的错误:对象引用未设置为对象的实例.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在以下代码中收到此错误:
I''m getting this error:
Object reference not set to an instance of an object.
在以下行中:
if (isDone.get_Value(oMissing).ToString() == "1")
:
using xlNS = Microsoft.Office.Interop.Excel;
xlNS.Range isDone;
isDone = targetSheet.get_Range("AA23", "AA23");
if (isDone.get_Value(oMissing).ToString() == "1")
{
//Do things
}
我的isDone原始值是:
My original value of isDone was:
isDone = targetSheet.get_Range("AA22", "AA22");
,但是我发现我正在覆盖AA22上的现有值,因此我将其转换为AA23.这个小小的变化导致了错误.我不知道为什么以及如何解决它...
but I found out that I was overwriting an existing value on AA22, so I turned it into AA23. this little change resulted in the error. I have no idea why and how to fix it...
推荐答案
我个人会尝试使用
I personally would try to use
if(targetSheet.Cells[22, 27].equals("1"))
{
//do things
}
这篇关于Excel对象上的错误:对象引用未设置为对象的实例.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文