I am Trying to read an Excel file using and finding the Start position for my another for loop.
This is my code.
public static int CheckStartPosition(String filename,int Colno,String StartChar, int sheetno,int startpos) {
try {
Workbook workbook = new Workbook();
workbook.open(filename);
Worksheet worksheet = workbook.getWorksheets().getSheet(sheetno);
Cells cells=worksheet.getCells();
int num=cells.getMaxDataRow();
int num1=cells.getMaxDataColumn();
int numofsheet= workbook.getNumberOfSheets();
System.out.println(numofsheet);
for (int n1=0;n1<=num;n1++) {
Cell cell1=cells.getCell(n1,Colno);
if(cell1.getValue()!=null) {
String value =cell1.getValue().toString().toLowerCase();
if(value.equals(StartChar)) {
System.out.println( cell1.getValue());
int S= cell1.getRowIndex();
startpos=S+1;
System.out.println(startpos);
}
}else{}
}
workbook.save("C:\\Movies.xls",FileFormatType.EXCEL97TO2003);
return startpos;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
:-
CheckStartPosition(f1.xls, 0,"abc",2,0);
How to return Startposition
It is a little hard to read due to formattign. CheckStartPosition() needs to return an int. In your catch block you don’t return anything. Return something. Or better yet declare CheckStartPosition with throws IOException and drop try catch from CheckStartPosition. Alternative use your own exception type.