system._comobject,while reading excel file

Experiences, small talk, and other automation gossip.
Posts: 1
Joined: Tue Jul 15, 2014 7:06 am

system._comobject,while reading excel file

Post by kmaheshguptha » Tue Jul 15, 2014 9:32 am

Hi friends,when I am executing following script,the content read from the excel showing as system._comObject.
can anyonce help in this.....

when I googled it I got the solution as xlRange.Cells[i,j].value2.ToString());
value2 fun/method/command not showing in the popup that comes on putting dot after xlRange.Cells[i,j].

using System;
using System.Threading;
using System.Drawing;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Reporting;
using Ranorex.Core.Testing;
using System.Windows.Forms;
using Office;
using Microsoft.Office.Interop.Excel;

namespace excelReadNDwrite
class Program
public static void Main(string[] args)
Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook =xlApp.Workbooks.Open(@"E:\MyExcelTest\keywordDriven.xls");
Excel.Worksheet xlWorkSheet = (Excel.Worksheet)(xlWorkbook.Worksheets.get_Item(3));
Excel.Range xlRange = xlWorkSheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
for (int i = 1; i <=3; i++)
for (int j = 1; j <= 3; j++)


User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Re: system._comobject,while reading excel file

Post by Support Team » Mon Jul 28, 2014 4:05 pm

Hi kmaheshguptha,

This is not really a Ranorex issue, but I think you have to cast the cell to a Excel.Range.
Please try the following code snippet in your for loop:
string myValue = (string)(xlRange.Cells[i,j] as Excel.Range).Value2;