0

I want to read values like 11610.1073 from excel using java and selenium. I tried below code but it throws me null pointer exception when I am trying to parse that value and store it in array variable. I am able to read int values but unable to do the same with the float values. Below is my code:

StagePTDFTE.add(Float.parseFloat(row.getCell(2).getStringCellValue().toString()));
StagePTDFTEArray = new float[StagePTDFTE.size()];
    for (int i = 0; i < StagePTDFTEArray.length; i++) {
        StagePTDFTEArray[i] = Float.parseFloat(df.format(StagePTDFTE.get(i)));
            }   

Please let me know where I am going wrong and what should be the modifications required here. Thanks in advance :)

1

1 Answer 1

1

Try using Data DataFormatter

All you need to do this:

// Only need one of these
DataFormatter fmt = new DataFormatter();

// Once per cell
String valueAsSeenInExcel = fmt.formatCellValue(cell);
Sign up to request clarification or add additional context in comments.

3 Comments

Yeah it works but the problem is if i want to read multiple values of that column then this doesnt work. It only reads last value of that particular column. So how can it be achieved ?
i sorted it out with the below code. Thanks so much @Siddhesh .
DataFormatter fmt = new DataFormatter(); overdueList.add(fmt.formatCellValue(row.getCell(4))); //Where //overdueList is String arraylist for (int i = 0; i < overdueList.size(); i++) { System.out.println("Values are " + overdueList.get(i).replace("%", "")); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.