0

I have a column that the cells format is like this : enter image description here

I have been being confused by this problem and I get this error "Cannot get a text value from a numeric cell". How can I get the cell contains integer value "2040" as string where as it has been formatted as text in the spreadsheet?

0

1 Answer 1

1

The class you're looking for is DataFormatter. Excel itself will normally store numbers in the file as CELL_TYPE_NUMERIC, with appropriate formatting rules to make them render as you expect. If you want to turn the double value + format rules into a String, DataFormatter will do that for you.

Your code can then look something like:

DataFormatter fmt = new DataFormatter();    

Row r = sheet.getRow(10);
Cell c = r.getCell(2, Row.RETURN_BLANK_AS_NULL);
if (c == null) {
   // There's no value in this cell
} else {
   System.out.println("Cell K2 is " + fmt.formatCellValue(c));
}
Sign up to request clarification or add additional context in comments.

1 Comment

it works fine for me. thanks a lot for your reply and help ^^

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.