mismas
mismas

Reputation: 1316

Number as it is from excel file using Apache POI

I am using Apache POI (version 3.9) framework for dealing with excel files, i.e. reading excel file.

I am having trouble with number types. User can write a number in excel file with comma or dot as decimal separator, i.e. 12.34 or 12,34, for various reasons.

Now, I would like to get that value as it is (i.e. if it is 12.34, then I would like to get 12.34, or if it is 12,34, then I would like to get 12,34), but instead POI Cell preliminary gives me a double with dot as decimal separator. So, if a cell value was 12,34, POI Cell would give double of value 12.34.

This behaviour is not what I would like to be. I would like to get the value that was entered (12,34).

How to avoid/solve this?

I have searched Stackoverflow for similar problems and tried to use solution given in thread How can I read numeric strings in Excel cells as string (not numbers) with Apache POI? and also tried using alternative org.apache.poi.ss.usermodel.DataFormatter class, and it works, but it does not work when the the value is 12,34 and type of cell is Number defined in Excel file itself.

Upvotes: 0

Views: 2013

Answers (1)

Gary Forbis
Gary Forbis

Reputation: 888

If you are validating the numbers, I would suggest that you might have more luck converting your validation string into a number to compare with the value in the cell. There is no information stored in the spreadsheet about the decimal/thousands separator. That is based on the locale set in the application or OS and is display-only - it is not stored at all. So you will have to manually format the number as a String.

Upvotes: 1

Related Questions