![](/img/trans.png)
[英]How to get number of rows in excel which contains data(excluding blank or empty cells) in one particular column using JAVA, APACHE POI
[英]Replacing blank number cells in Excel using Java
我正在遍歷 Excel 電子表格以使用 Java 獲取值。
每當我遇到一個空白的 String 單元格時,我都可以用 null 替換這個空白單元格。
但是,當嘗試對數值單元格執行相同操作時,我無法這樣做。
下面是我的代碼示例。
case 3:
String name;
if ("".equals(cell.getStringCellValue())) {
userType = "null";
} else {
userType = cell.getStringCellValue();
}
break;
case 4:
int hits;
hits = (int) cell.getNumericCellValue();
if(Integer.valueOf(hits) == 0) {
hits = 1;
}
任何人都可以告訴我我需要做什么來檢測單元格是否為空白並將此值替換為數字 1?
您可以檢查是否等於" "
,然后分配 1。您也可以嘗試解析為 int 並捕獲 if notANumberException
然后分配 1。
您現在正在做的是獲取 int 值,而它甚至可能不是 int 然后檢查是否為 0 而是"null" != null != 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.