Enter code here
.. I am trying to automate application through coded UI. I am stuck at this point:
Application has Table(ControlType : WinTable) and it is divided into 7 rows(ControlType : Row) like this:
FilePath : C:\test.txt
Printer Name : xyz
..
..
According to requirement, value of "FilePath" will take from excel sheet and same for "Printer name".
Here is the code:
WinWindow winP = new WinWindow();
winP.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.Name, "Create Print Job", PropertyExpressionOperator.Contains));
WinTable tbP = new WinTable(winP);
tbP.SearchProperties.Add(new PropertyExpression(WinTable.PropertyNames.Name, "Properties Window", PropertyExpressionOperator.Contains));
Excel.Workbook MyBook = null;
Excel.Application MyApp = null;
Excel.Worksheet MySheet = null;
MyApp = new Excel.Application();
MyApp.Visible = false;
MyBook = MyApp.Workbooks.Open("C:\\DEPCON\\DataInput.xlsx");
MySheet = (Excel.Worksheet)MyBook.Sheets[1];
Excel.Range range = MySheet.UsedRange;
for (int rCnt = 2; rCnt <= range.Rows.Count; rCnt++)
{
for (int cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
WinRow row = tbP.GetRow(0);
row.Value= (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; // row.Value is showing read only.
}
}
I also tried string[] values = tbP.GetContent();. Can anyone tell me how to assign a value on Row from excel sheet, one-by-one? I also checked WinTable function. All functions are related to get a value. I do not know how to set(assign) a value.