Reputation: 111
I want to read a particular row from excel. I already have the code to read from excel, but it's for all rows. I just want to read a particular row on basis of some condition.
File fis=new File("D:\\Sachin\\SOL.xls");
Workbook work=Workbook.getWorkbook(fis);
Sheet s=work.getSheet(0);
int rows=s.getRows();
int column=s.getColumns();
for(int i=0;i<rows;i++)
{
for(int j=0;j<column;j++)
{
Cell cell=s.getCell(j, i);
System.out.println(cell.getContents());
}
System.out.println("");
}
}
Upvotes: 2
Views: 9314
Reputation: 8387
Replacing this line:
Workbook work=Workbook.getWorkbook(fis);
With:
HSSFWorkbook work = new HSSFWorkbook(fis);
And try to use something like this:
HSSFWorkbook work = new HSSFWorkbook(fis);
HSSFSheet hssfSheet = work.getSheetAt(0);
for (int rn=startRowNo; rn<=endRowNo; rn++)
{
HSSFRow row = hssfSheet.getRow(rn);
// processing here your row
}
Upvotes: 2
Reputation: 388
I think you can use HSSFWorkBook here and then HSSFRow to get the row with row number.
HSSFRow row = hssfSheet.getRow(rn);
Upvotes: 0