wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes Finding file type XLS or XLSX using POI APIs. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Finding file type XLS or XLSX using POI APIs." Watch "Finding file type XLS or XLSX using POI APIs." New topic
Author

Finding file type XLS or XLSX using POI APIs.

Samir Banerjee
Ranch Hand

Joined: Jun 21, 2010
Posts: 72
This one is weird but if some one can help me out with this...
There is on function in our application where we pass the excel data as byte format :


now depending upon the file type xls or xlsx I want to do.

OR

Thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19757
    
  20

An XLSX file is actually just a special ZIP file. As such, its first two bytes are always PK (0x50 and 0x4B). You can even check the source of java.util.zip.ZipInputStream how it reads the first few bytes. Check the "src.zip" file inside your JDK installation.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42592
    
  65
Also be aware that the org.apache.poi.ss package contains classes that can hide the differences between both formats. For example, WorkbookFactory.create(InputStream) returns a Workbook you can use regardless of actual file format. Much better than having to code that yourself :-)


Ping & DNS - my free Android networking tools app
Samir Banerjee
Ranch Hand

Joined: Jun 21, 2010
Posts: 72
Thank you friends. Using org.apache.poi.ss package solved my problem as now I do not need to bother about the file type.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding file type XLS or XLSX using POI APIs.