How to access data from excel using the code

Ask general questions here.
NishantSingh
Posts: 39
Joined: Thu Oct 09, 2014 1:15 pm
Location: Bangalore

How to access data from excel using the code

Post by NishantSingh » Mon Nov 17, 2014 6:58 am

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
Regrads,
Nishant Singh

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to access data from excel using the code

Post by krstcs » Mon Nov 17, 2014 3:55 pm

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.
Shortcuts usually aren't...

Nagarjuna
Posts: 14
Joined: Fri Sep 26, 2014 6:23 am

Re: How to access data from excel using the code

Post by Nagarjuna » Wed Nov 19, 2014 12:50 pm

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

NishantSingh
Posts: 39
Joined: Thu Oct 09, 2014 1:15 pm
Location: Bangalore

Re: How to access data from excel using the code

Post by NishantSingh » Mon Nov 24, 2014 12:07 pm

Hi Nagarjuna,

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

regards,
Nishant Singh
Regrads,
Nishant Singh

vinod
Posts: 3
Joined: Fri Jan 02, 2015 12:32 pm

Re: How to access data from excel using the code

Post by vinod » Wed Jan 14, 2015 10:20 am

This is very helpful code to access data from any excel file with the help of code. Thanks to share this with us...

svelaga
Posts: 9
Joined: Fri Oct 30, 2015 7:43 pm

Re: How to access data from excel using the code

Post by svelaga » Fri Oct 30, 2015 7:59 pm

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

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

Re: How to access data from excel using the code

Post by Support Team » Mon Nov 02, 2015 3:17 pm

Hello svelaga,

Please try to use the following code:

Code: Select all

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