|
This is verified code.
Get test data from XLS and put into an array. Later we will split/iterate the whole array.
Got help from stackoverlow.com (could not recall exactly)
public void readexcelwithPOI(String excelname)
throws Exception
{
FileInputStream fileInputStream = new FileInputStream(excelname);
HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
HSSFSheet worksheet = workbook.getSheet("Sheet1");
for (int x=3;x<=20;x++)
{
HSSFRow row1 = worksheet.getRow(x);
//HSSFCell cellA1 = row1.getCell(2);
HSSFCell cellA1 =row1.getCell(2,org.apache.poi.ss.usermodel.Row.CREATE_NULL_AS_BLANK);
String a1Val = cellA1.getStringCellValue();
HSSFCell cellB1 =row1.getCell(3,org.apache.poi.ss.usermodel.Row.CREATE_NULL_AS_BLANK);
String b1Val = cellB1.getStringCellValue();
if (a1Val != ""){
if (fnames==null) {
fnames=a1Val.trim() + ";" + b1Val.trim() ;
}
else if((a1Val!=null) )
{
fnames = fnames + ";"+ a1Val.trim() +";" + b1Val.trim() ;
}
}
fnamearr= fnames.split(";");
}
} // method ends here
|