0
我收到一個錯誤:「無法從STRING單元格獲得NUMERIC值」,我確信這是因爲單元格爲空。我正在從xlsx讀取數據並將其寫入我的數據庫。有沒有人有一個簡單的方法來跳過空白單元格和進度?Java POI。當空白時跳過單元格
FileInputStream fileIn = new FileInputStream(filename);
Workbook wb = new XSSFWorkbook(fileIn);
Sheet sheet = wb.getSheetAt(0);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
Row row;
for (int i=1; i<=sheet.getLastRowNum(); i++){
row = sheet.getRow(i);
pst.setObject(1, row.getCell(0).getNumericCellValue());
pst.setString(2, row.getCell(1).getStringCellValue());
pst.setObject(3, sdf.format(row.getCell(2).getDateCellValue()));
pst.setObject(4, sdf.format(row.getCell(3).getDateCellValue()));
pst.setString(5, row.getCell(4).getStringCellValue());
pst.setObject(6, sdf.format(row.getCell(5).getDateCellValue()));
pst.setDouble(1, row.getCell(0).getNumericCellValue());
pst.execute();
}
wb.close();
fileIn.close();
pst.close();
rs.close();
loadDataFromDatabase();
}catch (SQLException ex){
Logger.getLogger(TestTableController.class.getName()).log(Level.SEVERE,null,ex);
}catch (IOException ex){
Logger.getLogger(TestTableController.class.getName()).log(Level.SEVERE,null,ex);
}
}
[Apache中POI跳過空白Excel細胞]的可能的複製(http://stackoverflow.com/questions/10405557/skipping-blank-excel-cells-in-apache-poi) – Peter