Excel codes are not working
Posted: Tue Jun 02, 2020 8:46 am
Hello,
I am trying to write some output values in an excel and for this I am using Excel Interop. But it is always throwing error in Value2.
The possible work around I did is as below but of no luck. Please support.
Tried replacing Value2 with Value - No luck
.Net framework used is 4.6.2 - No Luck
Error message is as below
'object' does not contain a definition for 'Value2' and no extension method 'Value2' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) (CS1061) - C:\Users\sd242\Documents\Ranorex\RanorexStudio Projects\Delet\Delet\Recording1.UserCode.cs:155,44
Assembly references being used.
using Microsoft.CSharp;
using xlObject = Microsoft.Office.Interop.Excel;
Code.
for (int i = 2; i < row; i++)
{
if (xlRange.Cells[i, 4].Value == ReferenceNumber)
{
row = i;
_TestFlag = true;
break;
}
}
if (_TestFlag != true)
{
xlRange.Cells[row, 2].Value2 = SerialNumber;
}
Please note the above code is working perfectly in Visual Studio
I am trying to write some output values in an excel and for this I am using Excel Interop. But it is always throwing error in Value2.
The possible work around I did is as below but of no luck. Please support.
Tried replacing Value2 with Value - No luck
.Net framework used is 4.6.2 - No Luck
Error message is as below
'object' does not contain a definition for 'Value2' and no extension method 'Value2' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) (CS1061) - C:\Users\sd242\Documents\Ranorex\RanorexStudio Projects\Delet\Delet\Recording1.UserCode.cs:155,44
Assembly references being used.
using Microsoft.CSharp;
using xlObject = Microsoft.Office.Interop.Excel;
Code.
for (int i = 2; i < row; i++)
{
if (xlRange.Cells[i, 4].Value == ReferenceNumber)
{
row = i;
_TestFlag = true;
break;
}
}
if (_TestFlag != true)
{
xlRange.Cells[row, 2].Value2 = SerialNumber;
}
Please note the above code is working perfectly in Visual Studio