Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding file type XLS or XLSX using POI APIs.

 
Samir Banerjee
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :-)
 
Samir Banerjee
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you friends. Using org.apache.poi.ss package solved my problem as now I do not need to bother about the file type.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic