• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Finding file type XLS or XLSX using POI APIs.

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A feeble attempt to tell you about our stuff that makes us money
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic