LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 30
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 ?
 
Old 07-27-2008, 08:48 AM   #2
amani
Senior Member
 
Registered: Jul 2006
Location: Kolkata, India
Distribution: 64-bit GNU/Linux, Kubuntu64, Fedora QA, Slackware,
Posts: 2,758

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
kshkid
Member
 
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
paulsm4
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:
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

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


Reply


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


All times are GMT -5. The time now is 07:24 AM.

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