-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)
4
  • 5
    upc is not a number to convert Commented Apr 7, 2017 at 7:26
  • Which number do you expect to get? Commented Apr 7, 2017 at 7:30
  • 2
    We can't see your data. How do you expect us to help? Commented Apr 7, 2017 at 7:31
  • assuming your first row is a header, you might have to start your int z = 1, not 0. Commented Apr 7, 2017 at 7:36

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.