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
saahil gupta
Ranch Hand
Joined: Dec 26, 2011
Posts: 64
posted
0
USE JExcel API
Johny Talker
Greenhorn
Joined: Jan 26, 2012
Posts: 13
posted
0
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: 2407
posted
0
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
posted
0
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: 2407
posted
0
No
Crypton Kid
Greenhorn
Joined: Jan 27, 2012
Posts: 1
posted
0
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
posted
0
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: 2407
posted
0
Sounds like the JExcelApi library is built to be run on Java 5.
Johny Talker
Greenhorn
Joined: Jan 26, 2012
Posts: 13
posted
0
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: 2407
posted
0
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
posted
0
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: 2407
posted
0
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
posted
0
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: 2407
posted
0
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
posted
0
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
posted
0
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: 2407
posted
0
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?
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.