如何检查Apache POI中数字单元格的空白?

时间:2021-02-04 20:26:06

All is in the title.

一切都在标题中。

How can I check if a CELL_TYPE_NUMERIC is empty with POI ? With strings i can use the isEmpty() method but with int I have no ideas (null is not allowed and zero just wont do it).

如何通过POI检查CELL_TYPE_NUMERIC是否为空?使用字符串我可以使用isEmpty()方法,但使用int我没有想法(不允许为null,零只是不会这样做)。

Thank you in advance.

先谢谢你。

2 个解决方案

#1


5  

Empty cells should not have format in POI since there is already a type for empty cells.

空单元格不应该在POI中具有格式,因为已存在空单元格的类型。

To check if the cell is empty you should test if the cell type is Cell.CELL_TYPE_BLANK. Sometimes empty cells do not exist in a Row; they will be null in this case.

要检查单元格是否为空,您应该测试单元格类型是否为Cel​​l.CELL_TYPE_BLANK。有时候空行中不存在空单元格;在这种情况下,它们将为null。

Hope it helped,

希望它有所帮助,

#2


0  

You can check the raw value of the cell

您可以检查单元格的原始值

public BigDecimal determinePorpertyValue(XSSFCell cell) {
    String rawValue = cell.getRawValue();
    return rawValue == null ? null : BigDecimal.valueOf(cell.getNumericCellValue());
}

#1


5  

Empty cells should not have format in POI since there is already a type for empty cells.

空单元格不应该在POI中具有格式,因为已存在空单元格的类型。

To check if the cell is empty you should test if the cell type is Cell.CELL_TYPE_BLANK. Sometimes empty cells do not exist in a Row; they will be null in this case.

要检查单元格是否为空,您应该测试单元格类型是否为Cel​​l.CELL_TYPE_BLANK。有时候空行中不存在空单元格;在这种情况下,它们将为null。

Hope it helped,

希望它有所帮助,

#2


0  

You can check the raw value of the cell

您可以检查单元格的原始值

public BigDecimal determinePorpertyValue(XSSFCell cell) {
    String rawValue = cell.getRawValue();
    return rawValue == null ? null : BigDecimal.valueOf(cell.getNumericCellValue());
}