1

in excel the value of column is 10101101010000000000 but when im reading it in java using POI the value is changed to 10101101009999999000, can anyone give me an idea on whats going on and how can i get the exact values from the excel. i've tried setting the celltype as string and use cell.getStringCellValue() and also this new BigDecimal(cell.getNumericCellValue()).toPlainString() but im still not getting the same value as with the excel

here's my code

List<BankClassVo> data = new ArrayList<BankClassVo>();
    FileInputStream fis = new FileInputStream(new File(Constant.VALIDATION_REFERENCE_FILE_PATH + Constant.BANK_CLASSIFICATION_REF_FILE + ".xlsx"));
    XSSFWorkbook myWorkBook = new XSSFWorkbook(fis);
    XSSFSheet mySheet = myWorkBook.getSheetAt(1);
    Iterator<Row> rowIterator = mySheet.iterator();


    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();
        Iterator<Cell> cellIterator = row.cellIterator();

        BankClassVo vo = new BankClassVo ();


            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                if (cell.getColumnIndex() == 0) {
                    vo.setsClass(new BigDecimal(cell.getNumericCellValue()).toPlainString());
                }
                else if (cell.getColumnIndex() == 1) {
                    vo.setClassification(cell.getStringCellValue());
                }
            }

        data.add(vo);
    }

    myWorkBook.close();
    return data;
6
  • 2
    You should probably add the code you're using to read the column Commented Jun 9, 2015 at 8:34
  • ok, ive added my code Commented Jun 9, 2015 at 8:40
  • I suggest you to read it as a string and then check if it's reading correctly. Commented Jun 9, 2015 at 8:48
  • @ Uma Kanth, yes ive already done that and still not reading correctly Commented Jun 9, 2015 at 8:51
  • 1
    XLSX stores as XML, so text. Just to make sure the problem is in Java: unzip the contents of your XLSX file and open xl/worksheets/sheet1.xml to see what the value actually is. Other than that, it looks like an overflow issue, perhaps in your BankClassVo class. Maybe first send cell.getStringCellValue() to System.out. Commented Jun 9, 2015 at 8:55

1 Answer 1

1

Use MathContext and RoundingMode. Ref

BigDecimal value = new BigDecimal(cell.getNumericCellValue(), new MathContext(10 , RoundingMode.CEILING));
System.out.println(value.toPlainString());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.