I get the following error when running the following code snippet in Ranorex 4.0.2:
"The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) (CS0234)"
The code snippet is:
---------
Code: Select all
using Excel = Microsoft.Office.Interop.Excel;
public void Validate_cell()
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
string str;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("C:\Users\Administrator\Desktop\Test_DataFile.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(Sheet1);
range = xlWorkSheet.UsedRange;
for (int rCnt = 2; rCnt <= range.Rows.Count; rCnt++) {
repo.row_index = Convert.ToString(rCnt);
for (int cCnt = 1; cCnt <= range.Columns.Count; cCnt++) {
repo.col_index = Convert.ToString(cCnt);
Report.Log(ReportLevel.Info, "Validation", "(Optional Action)\r\nValidating AttributeEqual (Class='checkmarkIcon') on item 'MPT.Cell'.", repo.MPT.CellInfo);
Validate.Attribute(repo.MPT.CellInfo, "Class", "checkmarkIcon", Validate.DefaultMessage, false);
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2 ;
MessageBox.Show(str);
}
}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
Any suggestions please.
Basically, I need to go to one cell at a time and read the value and compare it to a HTML table in the application. Are there any other ways to accomplish the same task.
Thanks,