So, to be clear, all you want to do is identify which files use the OpenXML file format and which are binary?
If so, then take a look at the org.apache.poi.ss.usermodel.WorkbookFactory (http://poi.eu.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFactory.html) class. All you need to do is call the static create method pasing an InputStream and you will receive back an instance of either the HSSF or XSSFWorkbook class depending upon the type of the file. Myself, I have never tried using it with files that lack extensions but it ought to work and I would certainly suggest giving it a try. Alternatively, you can simply catch exceptions; i.e. try to open the file as an HSSFWorkbook, catch the exception if the format is not correct and try to open it as an XSSFWorkbook then catch and handle the exception thrown if the format is again invalid. Finally, you could open an InputStream onto the file and examine the first few bytes - I think it is safe to assume that the xml header would be the first thing you read from an OpenXML based file. Yours Mark B Sparecreative wrote: > > We¹re currently successfully using poi in a webapp to read from uploaded > excel files. > > At present we do a check on the filename extension. If xls we use HSSF and > if xslx we use XSSF and this is working reasonably well. > > The problem we have is that some of our users are uploading files with no > extension. Is there a way to determine the type of excel file that we are > dealing with programmatically? > > I¹d appreciate any pointers as I haven¹t had a lot of luck finding > anything > on the web. > > Z. > > -- View this message in context: http://old.nabble.com/Determine-version-of-excel-file-tp26603831p26604556.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
