I debugged the programe n found out that i had wrong condition in second for loop it should be less than or equal to one or LastColumnNumber.
-------------------------------------
but I still get NULL pointer Exception for below lines
Please help.
nt s=xl.totalRowsInSheet(0);
System.out.println(s);
//int totalrows=xl.totalRowsInSheet(0);
----------------------------------------------------
for(int i=2;i<13;i++){
for(int j=0;j<=1;j++){
System.out.println(xl.getdata(0, i, j));
}
Hi Ashish,
I got the solution for this problem, but I really want to discuss about this problem.
Can we discuss it on skype?
Hi Ashish,
I have highlighted change in bold.
Please review the same.Is it a correct way or it can be done in some other way when using functions?
public class configxl {
HSSFSheet sht;
HSSFWorkbook wb;
HSSFRow row;
HSSFCell cell;
String data="";
FileInputStream file;
int totalrows;
String path;
[b:2ycjpemp] int sheetnum;[/b:2ycjpemp]
public configxl(String path) throws IOException
{
file = new FileInputStream(path);
wb = new HSSFWorkbook(file);
[b:2ycjpemp]sht = wb.getSheetAt(sheetnum);[/b:2ycjpemp]
}
/*public int getrowcount(int sheetn)
{
//totalrows=0;
wb.getSheetAt(sheetn);
totalrows= sht.getLastRowNum();
return totalrows;
}*/
public String getdata(int sheetn,int row,int col)
{
sht = wb.getSheetAt(sheetn);
cell= sht.getRow(row).getCell(col);
if(cell.getCellType()==cell.CELL_TYPE_NUMERIC)
{
String celltext=String.valueOf(cell.getNumericCellValue());
return celltext;
}
else{
if(cell.getCellType()==cell.CELL_TYPE_STRING)
data = cell.getStringCellValue();
return data;
}
}
public double NoofColumns(int sheetn,int rnum) throws IOException
{
int lastcellnum= sht.getRow(rnum).getLastCellNum();
return lastcellnum;
}
public int totalRowsInSheet(int sheetNum) throws IOException
{
//new configxl(path);
//sht = wb.getSheetAt(sheetNum);
int TotalRows=sht.getLastRowNum()-sht.getFirstRowNum();
return TotalRows;
}
}