Page 1 of 1

Problem With Excel

Posted: Thu May 15, 2014 2:52 pm
by Deepak_Singh
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.

Regrards,
Deepak

Re: Problem With Excel!!!

Posted: Thu May 15, 2014 3:37 pm
by mzperix
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,
Zoltan

Re: Problem With Excel!!!

Posted: Fri May 16, 2014 7:19 am
by Deepak_Singh
The Problem is that I want to store the Actual REsults in Excel.
Just that Plz help. :?

Ex:

Code: Select all

 If(repo.Ranorex.Ranorex.exists())
      {
         String x="Button Exists";
       }
       else
      {
          String x="Button Does not Exists";
      }
Depending on the Condition I want to store the Result in Excel. How will I do that? :?:

Regards,
Deepak :(

Re: Problem With Excel

Posted: Fri May 16, 2014 1:27 pm
by odklizec
Hi,

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:
http://www.ranorex.com/forum/writing-ex ... 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);
excelWorksheet.Activate();
// write something to cell 1,1
excelDataSourceFile.Cells[1,1] = "Button Exists";
// save excel file
excelWorkbook.Save();    
// close excel file
excelWorkbook.Close();

Re: Problem With Excel

Posted: Wed May 21, 2014 8:05 am
by Deepak_Singh
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!!!";  
                                                myExcelWorkbook.Save();
  			
  			myExcelApp.Visible = false;	

  			myExcelWorkbook.Close(); 
 

Regards,
Deepak :)