wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes How to identify the Microsoft office version  + POI 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 » Products » Other Open Source Projects
Bookmark "How to identify the Microsoft office version  + POI" Watch "How to identify the Microsoft office version  + POI" New topic
Author

How to identify the Microsoft office version + POI

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
Hi

I am using POI Version 3.6. and i am reading excel files using POI.

But is there anyway i can identify the version of excel file. because sometime .xls extension also needs XSSF as they are using the features of office 2007.

Regards,


Jigar Naik


Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Do you really need to know what format it is? The classes in the org.apache.poi.ss.usermodel package can handle both file formats.

If you do, try reading the file as a ZIP file (which the Office 2007 formats actually are) using the classes in java.util.zip; if you get an exception, then it's a binary (pre-office 2007) file.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
how do i read ?

Below is my code.

Currently i am just checking the extension. if the file extension is xls then call readExcel if its xlsx then call readExcel2007

Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
No need to do all that in your code, that's what the org.apache.poi.ss.usermodel package is for.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
But how do i read xls file.

I am not able to read xls. file using XSSF i need to use HSSF
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
ok. i got it.



Thanks
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
beautiful

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to identify the Microsoft office version + POI
 
Similar Threads
Excel document created using HSSF POI API not opening in Windows7 but opening in Win XP
Support for Chinese characters in POI API .
Opening an Excel file
error reading excel file using apache poi
Does POI require any office component on Server ?