-1

Hello,all I am trying to save the excel sheet data into MySQL database. For this i am using Apache Poi. I am getting cell values using DataFormatter in Apache Poi. I am getting cell values successfully as a string format, but i am trying to change the string value to Long I am getting NumberFormatException. I am trying the below code. Please try to solve my problem.

Thank you.

   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);
    .
    .
    .
    }

This is the error stack trace in console.

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)
sai
  • 27
  • 6

1 Answers1

1

I think all the cell value return by this code is not numeric value.

Cell upccell = firstSheet.getRow(z).getCell(0);

so you have to make sure that whatever the cell you are reading should contains numeric values.