[英]How to check for emptiness of a numeric cell in Apache POI?
All is in the title. 一切都在标题中。
How can I check if a CELL_TYPE_NUMERIC
is empty with POI ? 如何通过POI检查
CELL_TYPE_NUMERIC
是否为空? 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). 使用字符串我可以使用
isEmpty()
方法但是使用int
我没有想法(不允许为null,零只是不会这样做)。
Thank you in advance. 先感谢您。
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
. 要检查单元格是否为空,您应该测试单元格类型是否为
Cell.CELL_TYPE_BLANK
。 Sometimes empty cells do not exist in a Row
; 有时空单元格不以存在
Row
; they will be null
in this case. 在这种情况下,它们将为
null
。
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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.