• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to read xlsx file from local java file

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
USE JExcel API
 
Johny Talker
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like the JExcelApi library is built to be run on Java 5.
 
Johny Talker
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.FileNotFoundException:(The 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
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Johny Talker
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Thanks a lot for your inputs....

Finally problem resolved. I uses Aspose API for that and it works fine.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 80632
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:You are on an 11‑year old thread.


??? Looks like less than 2 years to me.
 
Campbell Ritchie
Marshal
Posts: 80632
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic