1

I am using linqtoexcel for my automation project. This file contains different site URL and its credentails. If I use only one row I am able to login to that site. But if there are two rows then I am having problem in using where clause.

Please help if you can if you do not understood anything please ask question.

  1. My excel Sheet

  2. Below is my code.

    string pathfile = @"..\..\Data.xlsx"; string sheetName = "Login"; var excelFile = new ExcelQueryFactory(pathfile); var abc = from a in excelFile.Worksheet(sheetName).AsEnumerable() where Row.Field<String>("ID").Trim() == "2" select a; PropertiesCollection.driver.Manage().Window.Maximize(); foreach (var a in abc) { PropertiesCollection.driver.Navigate().GoToUrl(a["URL"]); } foreach (var a in abc) { objLogin.Login(a["uname"], a["paswd"]); }

I know I am wrong as per my code. Also I know, I have an error in Field<String>

Please guide what will the better way to use where clause in linqtoexcel.

4

1 回答 1

1

This will help a specific row as per you condition. You just have to make changes in where clause.

string pathfile = @"..\..\Data.xlsx";
string sheetName = "Login";
var excelFile = new ExcelQueryFactory(pathfile);
var abc = from a in excelFile.Worksheet(sheetName).AsEnumerable() 
          where a["ID"] == "2" 
          select a;
PropertiesCollection.driver.Manage().Window.Maximize();
foreach (var a in abc)
{
PropertiesCollection.driver.Navigate().GoToUrl(a["URL"]);
}
foreach (var a in abc)
{
objLogin.Login(a["uname"], a["paswd"]);
}
于 2016-02-05T15:41:15.340 回答