poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Javen O'Neal" <one...@apache.org>
Subject Re: Query about WorkbookFactory.create(input)
Date Thu, 29 Oct 2015 08:02:32 GMT
Adding one more thing:

Here's the specific implementation:
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java?revision=1704710&view=markup#l196

    public static Workbook create(InputStream inp, String password)
throws IOException, InvalidFormatException, EncryptedDocumentException
{
        <SNIP>

        // Ensure that there is at least some data there
        byte[] header8 = IOUtils.peekFirst8Bytes(inp);

        // Try to create
        if (NPOIFSFileSystem.hasPOIFSHeader(header8)) {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(inp);
            return create(fs, password);
        }
        if (POIXMLDocument.hasOOXMLHeader(inp)) {
            return new XSSFWorkbook(OPCPackage.open(inp));
        }
        throw new InvalidFormatException("Your InputStream was neither
an OLE2 stream, nor an OOXML stream");
    }

WorkbookFactory.create is peeking at the first few bytes of the file
to guess what format it is. Note that POI does not support Excel 2007
Binary (XLSB) format.


On Wed, Oct 28, 2015 at 11:46 PM, Rohit Cha <rk661234567890@gmail.com> wrote:
> Does WorkbookFactory.create(input) can read both excel-2003 and excel-2007
> with out any exception or do we need to use xssf and hssf seperately for
> each one
>
>
> FileInputStream input = new FileInputStream(
>
> "/Users/Desktop/Spice+tool.xls");
>
>
> Workbook wb = WorkbookFactory.create(input);
>
> Sheet sheet = wb.getSheetAt(0);
>
> System.out.println(String.valueOf(sheet.getRow(11).getCell(0)));

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message