Search in sources :

Example 1 with SheetIterator

use of org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator in project poi by apache.

the class LoadPasswordProtectedXlsxStreaming method printSheetCount.

public static void printSheetCount(final InputStream inputStream) throws Exception {
    AesZipFileZipEntrySource source = AesZipFileZipEntrySource.createZipEntrySource(inputStream);
    try {
        OPCPackage pkg = OPCPackage.open(source);
        try {
            XSSFReader reader = new XSSFReader(pkg);
            SheetIterator iter = (SheetIterator) reader.getSheetsData();
            int count = 0;
            while (iter.hasNext()) {
                iter.next();
                count++;
            }
            System.out.println("sheet count: " + count);
        } finally {
            IOUtils.closeQuietly(pkg);
        }
    } finally {
        IOUtils.closeQuietly(source);
    }
}
Also used : AesZipFileZipEntrySource(org.apache.poi.poifs.crypt.temp.AesZipFileZipEntrySource) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) SheetIterator(org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader)

Aggregations

OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)1 AesZipFileZipEntrySource (org.apache.poi.poifs.crypt.temp.AesZipFileZipEntrySource)1 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)1 SheetIterator (org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator)1