Using C# to pull Excel values...

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Generally, I am getting access to Excel. I need to check for column header values. I can get excel and the file open. I am whileing through A1, A2, etc and I get the first value, but the same code on the second pass returns a NullReferenceException was unhandled error. Object Reference not set to an instance of the object. Not really sure why this would occur when the first pass was just fine??<br/> <br/>
<pre> while (i2 < iMax || sCellVal != strArrayColumns[i1-1]) //This loop checks each column header for the right value.
{
sTestVal = strArrayColumns[i1-1];//Grabs the value I am testing against.<br/>
sCellAddress = "A" + i2.ToString() ;
//Error is here in the following line on the second pass through.<br/>
sCellVal = xlSheet.get_Range(sCellAddress.ToString(), sCellAddress.ToString()).Value2.ToString();
i2++;
}[/code]
<br/> Any suggestions??<br/> <br/> Thanks,<br/> Dave<br/> <br/> <br/>

View the full article
 
Back
Top