gpt4 book ai didi

java - 从单元格值获取单元格索引,Apache POI

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:03:01 30 4
gpt4 key购买 nike

Environment    Status    Version    PatchNumber
Windows Live 1.0 2
Unix Live 2.0 4
Mac Live 1.3 8

如果我在 excel 中有上面显示的数据,我如何使用文本访问 PatchNumber 的 cellNumber

XSSFRow row = (XSSFRow) rows.next();
我想访问 row.getCellNumber("PatchNumber");//注意这个方法在 Apache POI 中不存在。

最佳答案

我想我明白您的意思 - 您想知道哪一列的第一行包含单词“Patch”?如果是这样,您需要做的就是:

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) {
// 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");
}

只需遍历第一行(标题)中的单元格,检查它们的值,并记下找到文本时所在的列!

关于java - 从单元格值获取单元格索引,Apache POI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12608551/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com