Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-27-2008, 04:03 AM   #1
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
reading integer values from excel using java - interprets it as float


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

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.

I see that both the issues are definitely unrelated.

Could you please provide some pointers on this ?
Old 07-27-2008, 08:48 AM   #2
Senior Member
Registered: Jul 2006
Location: Kolkata, India
Distribution: Debian 64-bit GNU/Linux, Kubuntu64, Fedora QA, Slackware,
Posts: 2,766

Rep: Reputation: Disabled
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.
Old 07-28-2008, 12:11 AM   #3
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
Thanks for the reply.

But I don't have any control over the input file format.
Old 07-28-2008, 12:53 AM   #4
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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:
  HSSFRow targetRow = targetWorkSheet.getRow(row);
  HSSFCell targetCell = targetRow.getCell((short) col);
  HSSFRichTextString hsfData = 
    new HSSFRichTextString(source_data);
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.


Here's a good link that might help with your POI "hello world":

Last edited by paulsm4; 07-28-2008 at 12:54 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
perl + excel + reading date values kshkid Programming 6 02-14-2008 01:13 PM
Convert float to integer in bash gn00kie Programming 2 07-30-2006 10:05 PM
Double/float to long integer bastl Programming 18 06-03-2006 09:24 AM
Reading excel files from c language rajesh_b Programming 4 11-25-2004 06:26 AM
can't convert o to FLoat in Java alaios Programming 4 04-24-2004 02:10 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:03 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration