I have Excel sheet with username, emailIDs, phone and location in different cells. I have added all the cell values into Arraylist. However, Now I need to loop through to indexes to read username each time and pass it to text boxes in other application.
I have written code till adding to ArrayList but not sure how to read each value from list every time and stuck here.
Means, first time I should read username as "A", email id "[email protected]", phone number as "12333", location as "xzy" from list. When loop continues second time, I should be able to read username "B" and values mapped to it.
public ArrayList<String> getdata() throws IOException {
FileInputStream fis = new FileInputStream("C:\\Users\\vnaditya\\Downloads\\Book2.xlsx");
XSSFWorkbook XS = new XSSFWorkbook(fis);
int numberofsheets = XS.getNumberOfSheets();
for(int i=0; i< numberofsheets; i++) {
if(XS.getSheetName(i).equalsIgnoreCase("Sheet1")) {
XSSFSheet XSS = XS.getSheetAt(i);
Iterator<Row> r = XSS.iterator();
while (r.hasNext()) {
Row row = r.next();
Iterator <Cell> cell = row.cellIterator();
while (cell.hasNext()) {
Cell cellvalue = cell.next();
String message = cellvalue.getStringCellValue();
System.out.println(message);
a.add(cellvalue.getStringCellValue());
// System.out.println(a);
// System.out.println(a.size());
}
}
}
}
Expected: need to read username and other cell values every time.