I created an Excel file name "readdata.xls" and entered some inputs like
UserName Password
Akshit Ak12345
Ashwika AS12345
I've written a code like this ....
package seleniumscripts;
import java.io.FileInputStream;
import jxl.Sheet;
import jxl.Workbook;
public class Excelreaddata {
private static String husername;
private static String hpassword;
private static String username;
private static String password;
public static void main(String[] args) throws Exception {
FileInputStream fis =new FileInputStream("C:\\Documents and Settings\\Home\\Desktop\\Readdata.xls");
Workbook wb = Workbook .getWorkbook(fis);
Sheet s= wb.getSheet(0);
Excelreaddata.husername =s.getCell(0,0).getContents();
Excelreaddata.hpassword =s.getCell(1,0).getContents();
System.out.println(Excelreaddata.husername);
System.out.println(Excelreaddata.hpassword);
Excelreaddata.username =s.getCell(0,1).getContents();
Excelreaddata.password =s.getCell(1,1).getContents();
System.out.println(Excelreaddata.username);
System.out.println(Excelreaddata.password);
Excelreaddata.username =s.getCell(0,2).getContents();
Excelreaddata.password =s.getCell(1,2).getContents();
System.out.println(Excelreaddata.username);
System.out.println(Excelreaddata.password);
}
}
My output result is ok.
My question is I want to shorten my code by using "for" or any other loop structure" i.e., I want to call the Excel data by writing in loop structure which should display all the usernames and passwords.
can any one help me this iam very much new to write code.