Reputation: 704
Hi i have following piece of code, here i have to return data which store in array s[][]
from this function, Please help how i can do it.
public static String[][] readxl(String filepath) throws FileNotFoundException, IOException
{
FileInputStream file = new FileInputStream(new File(filepath));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
int rowcount = sheet.getPhysicalNumberOfRows();
Row row1 = sheet.getRow(0);
int colcount=row1.getPhysicalNumberOfCells();
String[][]s = new String[rowcount][colcount];
for(int i=0;i<sheet.getPhysicalNumberOfRows();i++)
{
Row row = sheet.getRow(i);
for(int j=0; j<row.getPhysicalNumberOfCells();j++)
{
Cell c = sheet.getRow(i).getCell(j);
int celltype = c.getCellType();
if(celltype==1)
{
s[i][j] =c.getStringCellValue();
}
if(celltype==0)
{
s[i][j] =String.valueOf((int)c.getNumericCellValue());
}
}
}
Upvotes: 0
Views: 80
Reputation: 7057
You can directly use
return s;
There is no problem in returning an array even if size is dynamic.
Good luck.
Upvotes: 4