my dog learned polymorphism*
The moose likes I/O and Streams and the fly likes Text file xls to Binary format xls in Java. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Text file xls to Binary format xls in Java." Watch "Text file xls to Binary format xls in Java." New topic
Author

Text file xls to Binary format xls in Java.

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205


Hi,

I have text format xls file. I want to read it through POI. POI needs file in binray format of xls rather than text format xls.
so, my question is how to convert text file format to binary format xls in Java.

Thank you,
Rahul
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
XLS *is* a binary format, it is decidedly *not* a text format. So the question is: what kind of file have you got there? CSV?


Ping & DNS - my free Android networking tools app
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205

I am using COgnos SDK to generate XLS file. It's generate a XLS file but It's Save type is HTML and not Microsoft XLS. Hence My POI programs does not recognize the
XLS file and throws an exception.

Hope this helps.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
If it's saved as HTML, then it's not XLS. You need to save it as XLS, or use a library that can read HTML.
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205
Hi,

May be I was not able to specify you properly. I create a excel file using cognos SDK. It creates .xls file but it's text xls file rather than binary xls file.
when I open the file and try to save as I se as as in attached snap shot.

Please take a look at it and let me know is there any way in java I can change the file type to "Microsoft Excel workbook option" after the file creation.

Thank you,
Rahul



[Thumbnail for saveAs.jpg]

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
Again: there is no such thing as a "text XLS" file. XLS is a binary format, period. It's possible that you have a file that has an .xls extension for some reason but which is not an XLS file. If that's the case, someone messed up. Then the question is: what's in the file? What you posted is a save dialog, it doesn't tell us anything about the file contents.
Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 205

Yes, Contents of that file are same like other excel file

Please take a look at the following similar kind of problem

Click here
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
So it *is* an XLS file? So you just need to save it with a proper extension?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Text file xls to Binary format xls in Java.
 
Similar Threads
Creating Excel File - POI
Problem on opening .XLSX file
open an html file in excel
Help- how POI convert number cell to text?
generate large XLS file using java