我想我明白你在追求的是什么 – 你想知道哪一列中包含“Patch”这个词的第一行?如果是这样,您需要做的就是:
Sheet s = wb.getSheetAt(0);
Row r = s.getRow(0);
int patchColumn = -1;
for (int cn=0; cn
Cell c = r.getCell(cn);
if (c == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
// Can't be this cell - it's empty
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");
}
只需循环遍历第一行(标题)行中的单元格,检查它们的值,并在找到文本时记下您所在的列!