I think I understand what you need - do you want to know which column contains the word "Patch" in it in the first row? If so, all you have to do is something like:
Sheet s = wb.getSheetAt(0);
Row r = s.getRow(0);
int patchColumn = -1;
for (int cn=0; cn<r.getLastCellNum(); cn++) {
Cell c = r.getCell(cn);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
continue;
}
if (c.getCellType() == Cell.CELL_TYPE_STRING) {
String text = c.getStringCellValue();
if ("Patch".equals(text)) {
patchColumn = cn;
break;
}
}
}
if (patchColumn == -1) {
throw new Exception("None of the cells in the first row were Patch");
}
Just loop the cells in the first (header) row, check their value and mark the column you are in when you find the text!
source
share