In Ranorex
Ranorex Version: 5.4.4.26486
.NET Version: 4.0.30319.42000
Visual Studio
.NET Version: 4.6.00081
I am working on reading from an Excel sheet that is already open.
try { xl.Application excelApp = (xl.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); excelApp.Visible = true; xl.Workbook workbook = (xl.Workbook)excelApp.ActiveWorkbook; xl.Worksheet reportSheet = ((xl.Worksheet)workbook.Sheets[1]); xl.Range range = reportSheet.UsedRange; int rows = range.Rows.Count; int cols = range.Columns.Count; for(int i = 2; i < rows; i++) { for(int j = 1; j < cols; j++) { if(reportSheet.Cells[i,j].Value2 != null) { Console.WriteLine(range.Cells[i,j].Value2.ToString()); } else { Console.WriteLine("Empty Cell"); } } } Console.ReadKey(); } catch(Exception ex) { Report.Log(ReportLevel.Warn, "Module", "Failed to assign opened report to excelApp. " + ex.Message, new RecordItemIndex(1)); }The process works in Visual Studio. However when I try the exact same code in Ranorex it fails to build, giving me
'object' does not contain a definition for 'Value2' and no extension method 'Value2' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) (CS1061)
I believe this is a problem with a difference in versions, but I'm not sure how to approach the issue. Also I am not sure I'm reading from Excel in the best way. Any advice is appreciated.