如何通过编码的UI在Wintable行中分配值(来自excel)

时间:2014-06-17 14:11:13

标签: c# excel coded-ui-tests

Enter code here ..我正在尝试通过编码的UI自动化应用程序。我被困在这一点上:

应用程序有Table(ControlType:WinTable),它分为7行(ControlType:Row),如下所示:

FilePath:C:\ test.txt
打印机名称:xyz
..
..

根据要求," FilePath"将从excel表中获取,并且与#34;打印机名称"相同。

以下是代码:

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.  
                        }
        }

我也试过string [] values = tbP.GetContent();.任何人都可以告诉我如何从excel表中逐行分配一个值?我还检查了WinTable功能。所有函数都与获取值相关。我不知道如何设置(分配)一个值。

0 个答案:

没有答案