Problem With Excel

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
Posts: 76
Joined: Fri Mar 14, 2014 2:37 pm

Problem With Excel

Post by Deepak_Singh » Thu May 15, 2014 2:52 pm

Hi All,

I have seen a lot of posts about excel's.
Nut never got a satifying answer. All the code's given are complicated.

Scenario: I want to write data in different rows
Example: Coloumn "A" and rows 1 to 5.
How can I do that.

nd do i have to add some references to open excel?

Please Reply.

Last edited by Support Team on Fri May 16, 2014 7:18 am, edited 1 time in total.
Reason: offensive title

Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: Problem With Excel!!!

Post by mzperix » Thu May 15, 2014 3:37 pm

Hi Deepak,

The other day I did some automation on excel 2013. It went well :)

Just some things to make sure of:
- the ribbon should be always visible. Or use mousemoves, so the ribbon will stay visible.
- do not use automation on excel :D If you want to use it for creating and manipulating data, then use excel's built-in functions and macro programming. If you want to use it to create report, just use macros, and use ranorex .csv connectors to store data generated on the fly.

Why do you want to use Ranorex on excel automation in the first place anyway?

Best Regards,

Posts: 76
Joined: Fri Mar 14, 2014 2:37 pm

Re: Problem With Excel!!!

Post by Deepak_Singh » Fri May 16, 2014 7:19 am

The Problem is that I want to store the Actual REsults in Excel.
Just that Plz help. :?


Code: Select all

         String x="Button Exists";
          String x="Button Does not Exists";
Depending on the Condition I want to store the Result in Excel. How will I do that? :?:

Deepak :(

User avatar
Ranorex Guru
Ranorex Guru
Posts: 3921
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Problem With Excel

Post by odklizec » Fri May 16, 2014 1:27 pm


I'm afraid, there is not a direct (easy-to-use-without-coding) way how to write something to Excel. Below you can find a quick&dirty sample code how to write a string to an existing excel file (cell 1,1). It's just a rough example, which you will most probably have to adapt according your needs.

Other ways how to write something to excel are nicely summarized here: ... t1605.html

I personally would suggest to use Ranorex CSV data connector interface, which does not require Excel to be installed on the target machine.
// path to excel file
string xlsPath = @"c:\temp\rxtest.xls";
// desired sheet name
string currentSheet = "Sheet1";
// initialize excel
Excel.Application excelDataSourceFile = new Excel.ApplicationClass();  
// makes excel invisible
excelDataSourceFile.Visible = false;    
// opens excel file
Excel.Workbook excelWorkbook = excelDataSourceFile.Workbooks.Open(xlsPath);    		    
Excel.Sheets excelSheets = excelWorkbook.Worksheets;    
// set active sheet
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
// write something to cell 1,1
excelDataSourceFile.Cells[1,1] = "Button Exists";
// save excel file
// close excel file
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Posts: 76
Joined: Fri Mar 14, 2014 2:37 pm

Re: Problem With Excel

Post by Deepak_Singh » Wed May 21, 2014 8:05 am

For Future Reference.This will help: Just Copy and Paste from here.

Code: Select all

 Excel.Application myExcelApp;
        	Excel.Workbooks myExcelWorkbooks;
        	Excel.Workbook myExcelWorkbook;
        	object misValue = System.Reflection.Missing.Value;
        	myExcelApp = new Excel.ApplicationClass();
        	myExcelApp.Visible = true;
 			myExcelWorkbooks = myExcelApp.Workbooks;
 			String fileName = "C:\Change_Password_Blank_spaces.xls"; 
 			// set this to your file you want
  			myExcelWorkbook = myExcelWorkbooks.Open(fileName);
                                                myExcelApp.Cells[row,Coloumn]="Step Failed!!!";  
  			myExcelApp.Visible = false;	


Deepak :)