-2
你好,我試圖將excel表單數據保存到MySQL數據庫中。 爲此,我使用Apache Poi。我在Apache Poi中使用DataFormatter獲取單元格值。我獲得單元格值作爲字符串格式成功,但我試圖將字符串值更改爲長我得到NumberFormatException。我正在嘗試下面的代碼。請嘗試解決我的問題。java.lang.NumberFormatException:對於輸入字符串:「」
謝謝。
FileInputStream inputStream = new FileInputStream(filename);
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XSSFSheet firstSheet = workbook.getSheetAt(0);
DataFormatter formatter = new DataFormatter();
for(int z=0;z<firstSheet.getLastRowNum();z++)
{
Cell upccell=firstSheet.getRow(z).getCell(0);
String upcstring =formatter.formatCellValue(upccell);
long upc=Long.valueOf(upcstring);
.
.
.
}
這是控制檯中的錯誤堆棧跟蹤。
java.lang.NumberFormatException: For input string: "upc"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.<init>(Unknown Source)
'upc'不是一個數字轉換 – Satya
哪個號碼你希望得到什麼? –
我們無法看到您的數據。你如何期望我們提供幫助? –