I am using a program to read values from an excel file and then return the read values. I have tried using an iterator as well as a for loop but the program does not return all the values in the worksheet. Please suggest.
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import java.io.File;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelReading {
public static STring ReadExcel(String Path){
String FakeReturn = null;
try
{
FileInputStream file = new FileInputStream(new File(Path));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
for(Row row:sheet)
{
Cell cell=row.getCell(0);
Cell testcell = row.getCell(1);
if(cell.getStringCellValue()!=null)
return testcell.getStringCellValue();
else
break;
}
file.close();
}
catch (Exception e)
{
System.out.println("The code carries an exception");
e.printStackTrace();
return FakeReturn;
}
return FakeReturn;
}
}