1

I am able to fetch the values from an excel sheet, I have 20 columns in my sheet where 7th and 8th columns are date type cells like 7-Mar-2015, I am able to fetch the string/text values properly but not able to fetch the date format cells, and getting an error, I tried changing the type to get the cell values but not happening, can anyone help me how can I get both text/String OR Date format cells in my while loop,'

My code is as follows,

while (iterator.hasNext()) {
            Row nextRow = iterator.next();
            Map<Field, String> values = new EnumMap(Field.class);
            for (Field f : Field.values()) {
                Cell cell = nextRow.getCell(f.ordinal());
                if (cell != null) {
                    values.put(f, cell.getStringCellValue());
                }
            } 

The date format is 7-Mar-2015

1 Answer 1

2

try to check the format of the cell and then extract the value with correct funtion,

for reference,

if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC){
        if (DateUtil.isCellDateFormatted(cell)) {
            System.out.println(cell.getDateCellValue());
        } else {
            System.out.println(cell.getNumericCellValue());
        }
}
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.