aspose file tools*
The moose likes Java in General and the fly likes How to read xlsx file from local java file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to read xlsx file from local java file" Watch "How to read xlsx file from local java file" New topic
Author

How to read xlsx file from local java file

Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
Hi Experts,

I want to create a local java file to read a xlsx-file . I have gone through some code such as using POI-3.5 (which is for jdk 1.5) but I want to do it using jdk 1.4.
Can anyone help me into this ?
Thanks in advance
Ifteqar Ald
Ranch Hand

Joined: Dec 26, 2011
Posts: 73
USE JExcel API
Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
Thanks a lot for reply .....

But can you give me some more information about it .... such as do i need to create a xlsx file ?
Do you have any weblink or document which can help me to understand it.....
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
POI is the only Java library that can handle XLSX files, and it needs Java 5. Note that even Java 5 has been obsolete for a couple of years now, so you should start by upgrading the JVM to something much more recent.

do i need to create a xlsx file ?

Not sure what you're asking; you said you wanted to read files, not create them ... ? But regardless, POI can do both.

Do you have any weblink or document which can help me to understand it

The POI web site has a page full of example code for all kinds of things that the library can do with XLS/XLSX files.
Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
Hi Tim, Thanks for reply.

I have got code for the same using POI-3.5 but as i have mentioned, I need to implement this requirement using jdk 1.4 which is mandatory . So it will be helpful, if you can help me to do this using jdk 1.4
Is there any API with tutorial for this which supports jdk 1.4 ?
thanks once again for your time ...
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
No
Crypton Kid
Greenhorn

Joined: Jan 27, 2012
Posts: 1
Hi
With JDK1.4 you can only handle ".xls" format file i.e. microsoft office up to 2003 version. It does not have any applications / jar files to support .xlsx format.
One can read and write the excel files using "jxl.jar" jar file and to understand more on it you can use following link
"http://www.andykhan.com/jexcelapi/tutorial.html"
Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
Hi,
Now my code looks like the following :

I have included jxl.jar and using jdk 1.4 . And I am using MS-Office 2007. But while running my code, I am getting following erroe message:

java.lang.UnsupportedClassVersionError: jxl/read/biff/BiffException (Unsupported major.minor version 50.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"


Any idea about this?

[moderator edit: added code tags]
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Sounds like the JExcelApi library is built to be run on Java 5.
Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
Is this error having any relation to MS-Office version? As I am using MSOffice 2007, while jdk 1.4 supports only upto 2003. (point out if i am wrong).

IF JExcel-API doesn't supports jdk1.4, then what is alternative to do this using jdk 1.4
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
It has nothing to do with the files, it has to do with the fact that you're using Java 1.4. I'm not aware of a current library that can read any kind of Excel file and still runs on Java 1.4.

Old versions of POI (pre-3.5) and -most likely- older version of JExcelApi should be able to run on 1.4. Or you can grab the source code of JExcelApi and try to compile it for Java 1.4; maybe the work required is not all that much. Of course, it could be a lot of work.

But if you're looking at JExcelApi, then you have already resigned yourself to not support XLSX, so you might as well start with POI 3.2 and see if that works.
Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
Hi Tim,

I even tried to code using POI-3.2-FINAL-20081019.jar but again not successful. But I got to know that It has to do something with version of MS-Office file.
I am getting the following error while giving the extension as XLS :

org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. POI only supports OLE2 Office documents
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockReader.java:108)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:312)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:293)
at readPOI.readDataToExcelFile(readPOI.java:18)
at readPOI.main(readPOI.java:12)


And when giving file extension as XLSX :

java.io.FileNotFoundException: C:\Documents and Settings\abc\Desktop\Book1.xls (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at readPOI.readDataToExcelFile(readPOI.java:17)
at readPOI.main(readPOI.java:12)

Anyone having any idea what's going on ....
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Changing the file extension from .xlsx to .xls does not make the file an XLS file. As has been mentioned before POI versions pre-3.5 can't handle XLSX.
Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
But when i save the file(Excel 2007) as 97-03, my code is working fine ...
as per my code line :
String fileName = "C:/Documents and Settings/abc/Desktop/Book.xls"; ------ its working file after saving file in 97-03


While when i change it to :
String fileName = "C:/Documents and Settings/ysingh/Desktop/Book.xlsx"; ------- its giving java.io.FileNotFoundExceptionThe system cannot find the file specified)




but still it doesn't meet the requirement as i have to read an xlsx-file, not xls.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Once more: XLS is a different format than XLSX. Just because a library can read XLS does not mean it can read XLSX. jExcelApi can't read XLSX. POI pre-3.5 can't read XLSX; POI 3.5 and later can read it, but requires Java 5. Those are the facts.

There are commcercial APIs for handling Excel files (Aspose comes to mind), but I doubt that they run on Java 1.4; their support can tell you for sure.
Shahzad Latif
Greenhorn

Joined: Apr 28, 2011
Posts: 28
Hi Tim, Johny,

I would like to share that Aspose.Cells for Java supports JDK 1.4 and above. It can also create and manipulate both XLS and XLSX files. You may also try the evaluation version at your end to see if it satisfies all of your requirements.


Developer Evangelist @ Aspose. I love to explore and learn new technologies and help other developers along the way.
Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
Hi,

Does anyone know how to use SmartXLS-API or Aspose-API ?
I found that Aspose can fulfill these requirement but I am not able to write the code to use it .....
So if anybody having any idea about it, please share it ..

Thanks
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Shouldn't a commercial product come with support? Or have extensive information available on their site? What did you find, and what is still missing?
Shahzad Latif
Greenhorn

Joined: Apr 28, 2011
Posts: 28
Hi Johny,

You can either view the complete documentation with examples or contact Aspose.Cells support team for further help. If you're having any issue while using the component, please share the details.
Johny Talker
Greenhorn

Joined: Jan 26, 2012
Posts: 13
Hi All,
Thanks a lot for your inputs....

Finally problem resolved. I uses Aspose API for that and it works fine.
Calin Ursu
Greenhorn

Joined: Dec 12, 2012
Posts: 1
Guys, I also found this library that supports JRE 1.4 or above. User guide is available at http://www.easyxls.com/manual/index.html
bala gi
Greenhorn

Joined: Oct 01, 2012
Posts: 2
Hi Guys,

I was getting "Excel found unreadable content.... " error when tried to open xls file in WINS7/Excel 2007. But the same was working in XP/Excel 2007.
The code(java version - JDK1.4, POI version - 1.5.1) was using HSSF usermodel to create xls file.

I have found a POI jar from http://en.sourceforge.jp/projects/poi-jdk14/howto/install. It is mentioned that POI3.8 is migrated to use with JDK1.4.

Now i changed to use SS usermodel with the help of the above POI and it worked for me.

Can anyone please suggest whether it is safe to use this jar from this site ?

Appreciate your help on this!
nurvasi nurvas
Greenhorn

Joined: Nov 19, 2013
Posts: 1
Johny Talker wrote:Hi All,
Thanks a lot for your inputs....

Finally problem resolved. I uses Aspose API for that and it works fine.


Hi Johnny,

I have the same problem, I need read xlsx with jdk 1.4, can you help me??

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Welcome to the Ranch

You are on an 11‑year old thread. I doubt he will be around to answer, so please tell us the details of your problem.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42282
    
  64
nurvasi nurvas wrote:can you help me?

Help with what, exactly? This topic mentions two apparent solutions -Aspose and some JDK 1.4 port of POI-, are you asking about one of those? Or does neither work for you, and you're looking for something else?

By the way, using Java 1.4 (and even Java 5) for anything in a professional setting at this point is akin to criminal negligence, given all the unpatched security holes that have been discovered over the years. You need to raise this issue with whoever can affect change about that.
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Campbell Ritchie wrote:You are on an 11‑year old thread.

??? Looks like less than 2 years to me.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Stuart A. Burkett wrote:
Campbell Ritchie wrote:You are on an 11‑year old thread.

??? Looks like less than 2 years to me.
11 is definitely less than 2.


Well it is now
What a mistake! Sorry.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to read xlsx file from local java file