Page 1 of 1

How to access data from excel using the code

Posted: Mon Nov 17, 2014 6:58 am
by NishantSingh
Hi,

Out of curiosity wanted to know is there any possiblity to access and manupulate data in and from the excel without using the Inbuilt excelconnector GUI function can we do it by writing some code in Ranorex studio 5.2 ?

If it is possible Please let me know how to do it.

Regards
Nishant Singh

Re: How to access data from excel using the code

Posted: Mon Nov 17, 2014 3:55 pm
by krstcs
Ranorex is built on .NET, so anything you can do with .NET you can do with Ranorex.

A couple of things to note:
1. It is NOT advisable to manipulate test data during the test run.
2. You will need to know how to write .NET code.

Use the .NET Office Interoperability library just like you would any other library. There are numerous examples of how it works on the web.

Re: How to access data from excel using the code

Posted: Wed Nov 19, 2014 12:50 pm
by Nagarjuna
Hi,

Hope below peace of code will help to read Excel File in the ranorex code modules.

Excel.Application excelFile = new Excel.ApplicationClass();
Excel.Workbook excelWB= excelFile.Workbooks.Open(path);
Excel.Worksheet excelWS=(Excel.Worksheet) excelWB.Worksheets.get_Item(sheetName);

Exce.Range tmpRange=(Excel.Range)excelWS.Cells[1,1];
sting cellText=tmpRange.Text.ToString();

Regards,
Nagarjuna

Re: How to access data from excel using the code

Posted: Mon Nov 24, 2014 12:07 pm
by NishantSingh
Hi Nagarjuna,

Thanks for the code script I already got that from other sources. but anyways thanks for reponse.

regards,
Nishant Singh

Re: How to access data from excel using the code

Posted: Wed Jan 14, 2015 10:20 am
by vinod
This is very helpful code to access data from any excel file with the help of code. Thanks to share this with us...

Re: How to access data from excel using the code

Posted: Fri Oct 30, 2015 7:59 pm
by svelaga
Can you please let me know how the path of the excel document need to be given , as I have tried couple of ways but getting error
1) I have my excel sheet with in the project folder as
C:\\MyRanorex\\TripMaker_Consumer\\InputData.xls

2) The code I have written is
Excel.Application excelFile = new Excel.ApplicationClass();
Excel.Workbook excelWB = excelFile.Workbooks.Open("C:\\MyRanorex\\TripMaker_Consumer\\InputData.xls");
Excel.Worksheet excelWS = (Excel.Worksheet)
excelWB.Worksheets.get_item(Sheet1);

Excel.Range tmpRange = (Excel.Range)excelWS.Cells[1,1];
string value = tmpRange.Text.ToString();
Report.Info(value);

Please correct me with the right information

Re: How to access data from excel using the code

Posted: Mon Nov 02, 2015 3:17 pm
by Support Team
Hello svelaga,

Please try to use the following code:

Code: Select all

…Open(@"C:\MyRanorex\TripMaker_Consumer\InputData.xls");
Regards,
Robert