LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   reading integer values from excel using java - interprets it as float (https://www.linuxquestions.org/questions/programming-9/reading-integer-values-from-excel-using-java-interprets-it-as-float-658521/)

kshkid 07-27-2008 04:03 AM

reading integer values from excel using java - interprets it as float
 
Hello,

Am using Jakarta POI libraries for reading excel file using Java.

Reading string value is really easy and no issues with that.
But when it comes to reading a integer value like 112, its interpreting and displaying it as 112.0

So all my data in the output sheet looks like transformed to float values.

This is how I write the data

Code:

HSSFRow targetRow = targetWorkSheet.getRow(row);
HSSFCell targetCell = targetRow.getCell((short) col);
targetCell.setCellValue(new HSSFRichTextString(source_data));

This thread is definitely not a duplicate of the thread I had posted earlier.

http://www.linuxquestions.org/questi...t-java-658520/

I see that both the issues are definitely unrelated.

Could you please provide some pointers on this ?

amani 07-27-2008 08:48 AM

Why don't you read a more stable format like csv or good quality xml based ones?
In R programming, we strictly avoid the excel format.

kshkid 07-28-2008 12:11 AM

Thanks for the reply.

But I don't have any control over the input file format.

paulsm4 07-28-2008 12:53 AM

Hi -

I agree - this is a seperate issue from your other post. But my advice is similar: "don't assume anything - carefully check each of your intermediate values carefully". For example:
Code:

  HSSFRow targetRow = targetWorkSheet.getRow(row);
  HSSFCell targetCell = targetRow.getCell((short) col);
  HSSFRichTextString hsfData =
    new HSSFRichTextString(source_data);

  targetCell.setCellValue(hsfData);

It might also be a "representation issue" - the actual value is probably stored in the cell as a "variant" (it can be any type), but it's displayed as whatever the cell is configured to display (by default, perhaps this might be "float").

If you print out "hsfData" (as a seperate value), at least you know it's correct before you put it into the cell. Then you might try "setCellStyle()" (or something like that) to see if that changes the way it appears.

Moreover, I'd strongly suggest writing a standalone Java/POI "hello world" with dummy data. Do this *before* you actually try to write your translator. I think having the standalone test program will make life *much* easier for you as you attempt to troubleshoot your actual project.

IMHO .. PSM

PS:
Here's a good link that might help with your POI "hello world":
http://www.devx.com/java/Article/17301/1954


All times are GMT -5. The time now is 01:20 AM.