![](/img/trans.png)
[英]Print the Empty cell Adjacent cell value in Excel Sheet using Java
[英]Reading Empty Cell of Excel Sheet
我正在使用以下代碼讀取Excel工作表的內容。
for (Row row : sheet) {
Cell firstCell = row.getCell(0);
Cell secondCell = row.getCell(1);
Cell thirdCell = row.getCell(2);
Cell fourthCell = row.getCell(3);
Cell fifthCell = row.getCell(4);
urlcnt=firstCell.getRichStringCellValue().getString();
srccnt=secondCell.getRichStringCellValue().getString();
contentType=thirdCell.getRichStringCellValue().getString();
verticle=fourthCell.getRichStringCellValue().getString();
timeFrame=fifthCell.getRichStringCellValue().getString();
}
我如上所述將特定行的每個單元格分配給一個字符串。
PreparedStatement insertUrlStatement = con.prepareStatement("INSERT INTO urls_temp(url, source_name, is_active, is_periodic, Link_Type, New_Entry, verticle, periodic_timeframe, datentime) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
insertUrlStatement.setString(1, urlcnt);
insertUrlStatement.setString(2, srccnt);
insertUrlStatement.setInt(3, 1);
insertUrlStatement.setInt(4, 0);
insertUrlStatement.setString(5, contentType);
insertUrlStatement.setInt(6, 1);
insertUrlStatement.setString(7, verticle);
insertUrlStatement.setString(8, timeFrame);
insertUrlStatement.setString(9, datentime);
insertUrlStatement.executeUpdate();
有時,在Excel工作表中,用戶可能會連續將單元格留空。 在這種情況下,該程序不會插入整個行。
我希望將空單元格保存為表urls_temp中的null。
如何達到相同? 請指教...
這可能是個主意。 如果提供的變量為空,則使用在語句中填充null的函數。 您可能需要嘗試使用(text = null)部分,但這可以完成工作。 對不起,我的編碼風格不佳。 對於任何數據類型,您都將需要這樣的函數。
function bindString(int column, String text) {
If (text == null) then
insertUrlStatement.setNull(column, STRING);
Else
insertUrlStatement.setString(column, text);
EndIf
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.