0

Following is the code I used for extracting any value from excel sheet. Cell value can be string ,date or long int. Using below code I am able to extract string and date correctly but long int values are coming in as 4.6861230317E10 instead of 46861230317. How to overcome this issue??

 Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum); 
                if(Cell.getCellTypeEnum() == CellType.STRING)
                {

                    System.out.println("check for celltype string");
                    CellData = Cell.getStringCellValue();
                    System.out.println("String CellData:"+CellData);
                }   
                else  
                if(Cell.getCellTypeEnum() == CellType.NUMERIC)
                {
                    System.out.println("checking for celltype numeric");
                    CellData = fmt.formatCellValue(Cell);
                    if(CellData.contains("/"))
                    {
                        System.out.println("its a date !"+CellData);
                    }
                    else if(!CellData.contains("/"))
                    {

                        double  CellData2 = (double)Cell.getNumericCellValue(); 
                        System.out.println("actual double value "+CellData2);
                        CellData=String.valueOf(CellData2);
                        System.out.println("its a double int numeric value "+CellData);

                    }

                }   
                System.out.println("returning cell data "+CellData);
                return CellData;

2 Answers 2

1

Try following line implementation in your code

cell.setCellType(Cell.CELL_TYPE_STRING)

It worked for me.

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

Comments

0

Instead of

double  CellData2 = (double)Cell.getNumericCellValue(); 

use

long CellData2 = new Double(Cell.getNumericCellValue()).longValue();  

It works just fine too !!!

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.