Example usage for org.apache.poi.poifs.filesystem DocumentFactoryHelper hasOOXMLHeader

List of usage examples for org.apache.poi.poifs.filesystem DocumentFactoryHelper hasOOXMLHeader

Introduction

In this page you can find the example usage for org.apache.poi.poifs.filesystem DocumentFactoryHelper hasOOXMLHeader.

Prototype

@Deprecated
@Removal(version = "4.0")
public static boolean hasOOXMLHeader(InputStream inp) throws IOException 

Source Link

Document

Checks that the supplied InputStream (which MUST support mark and reset) has a OOXML (zip) header at the start of it.

If unsure if your InputStream does support mark / reset, use FileMagic#prepareToCheckMagic(InputStream) to wrap it and make sure to always use that, and not the original!

Usage

From source file:com.netsteadfast.greenstep.util.SimpleUtils.java

License:Apache License

/**
 * http://stackoverflow.com/questions/12593752/why-do-i-failed-to-read-excel-2007-using-poi
 * /*from w w  w  .j av  a2  s. c om*/
 * @param inp
 * @return
 * @throws IOException
 * @throws InvalidFormatException
 */
public static Workbook createPOIWorkbook(InputStream inp) throws IOException, InvalidFormatException {
    // If clearly doesn't do mark/reset, wrap up
    if (!inp.markSupported()) {
        inp = new PushbackInputStream(inp, 8);
    }
    if (POIFSFileSystem.hasPOIFSHeader(inp)) {
        return new HSSFWorkbook(inp);
    }
    if (DocumentFactoryHelper.hasOOXMLHeader(inp)) {
        return new XSSFWorkbook(OPCPackage.open(inp));
    }
    throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
}