gpt4 book ai didi

java - 使用 XSSF 在 Excel 工作表中的空单元格的结果地址

转载 作者:行者123 更新时间:2023-12-02 16:58:11 27 4
gpt4 key购买 nike

我正在使用 POI 的 XSSF 读取 Excel 工作表。 Excel 工作表有数千行用户信息,如用户名、地址、年龄、部门等。

我可以成功读取和写入 Excel 工作表,但我想找到空/空单元格的地址,并希望将其作为结果打印在另一张工作表中

我想要的示例结果是:

Empty cell  : C5
Empty cell : E7
Empty cell : H8

感谢并感谢您的讨论和回复。

最佳答案

您需要检查 Null 和 Blank 单元格。空单元格是从未使用过的单元格,空白单元格是已使用或以某种方式设置样式的单元格,Excel 决定将它们保留在文件中

控制此抓取的最简单方法是使用 MissingCellPolicy 。您的代码可以是这样的:

Row r = getRow(); // Logic here to get the row of interest

// Iterate over all cells in the row, up to at least the 10th column
int lastColumn = Math.max(r.getLastCellNum(), 10);

for (int cn = 0; cn < lastColumn; cn++) {
Cell c = r.getCell(cn, Row.RETURN_BLANK_AS_NULL);
if (c == null) {
// The spreadsheet is empty in this cell
} else {
// Do something useful with the cell's contents
// eg...
System.out.println("There is data in cell " + (new CellReference(c)).formatAsString());
}
}

您可以在POI docs on iterating over rows and cells中找到更多相关信息。

关于java - 使用 XSSF 在 Excel 工作表中的空单元格的结果地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24803315/

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