mirror of
https://github.com/apache/poi.git
synced 2025-03-06 08:59:07 +00:00
[bug-69411] add XSSFReader.getSheetIterator
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921571 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a528d43590
commit
c9c8653e6e
@ -20,12 +20,12 @@
|
|||||||
package org.apache.poi.examples.xssf.eventusermodel;
|
package org.apache.poi.examples.xssf.eventusermodel;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.poi.examples.xssf.usermodel.LoadPasswordProtectedXlsx;
|
import org.apache.poi.examples.xssf.usermodel.LoadPasswordProtectedXlsx;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.poifs.crypt.temp.AesZipFileZipEntrySource;
|
import org.apache.poi.poifs.crypt.temp.AesZipFileZipEntrySource;
|
||||||
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
||||||
import org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An example that loads a password protected workbook and counts the sheets.
|
* An example that loads a password protected workbook and counts the sheets.
|
||||||
@ -48,11 +48,12 @@ public final class LoadPasswordProtectedXlsxStreaming {
|
|||||||
try (AesZipFileZipEntrySource source = AesZipFileZipEntrySource.createZipEntrySource(inputStream);
|
try (AesZipFileZipEntrySource source = AesZipFileZipEntrySource.createZipEntrySource(inputStream);
|
||||||
OPCPackage pkg = OPCPackage.open(source)) {
|
OPCPackage pkg = OPCPackage.open(source)) {
|
||||||
XSSFReader reader = new XSSFReader(pkg);
|
XSSFReader reader = new XSSFReader(pkg);
|
||||||
SheetIterator iter = (SheetIterator)reader.getSheetsData();
|
Iterator<InputStream> iter = reader.getSheetsData();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while(iter.hasNext()) {
|
while(iter.hasNext()) {
|
||||||
iter.next();
|
try (InputStream stream = iter.next()) {
|
||||||
count++;
|
count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
System.out.println("sheet count: " + count);
|
System.out.println("sheet count: " + count);
|
||||||
}
|
}
|
||||||
|
@ -107,9 +107,10 @@ public class XSSFBReader extends XSSFReader {
|
|||||||
* @return iterator of {@link InputStream}s
|
* @return iterator of {@link InputStream}s
|
||||||
* @throws InvalidFormatException if the sheet data format is invalid
|
* @throws InvalidFormatException if the sheet data format is invalid
|
||||||
* @throws IOException if there is an I/O issue reading the data
|
* @throws IOException if there is an I/O issue reading the data
|
||||||
|
* @since POI 5.3.1
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Iterator<InputStream> getSheetsData() throws IOException, InvalidFormatException {
|
public SheetIterator getSheetIterator() throws IOException, InvalidFormatException {
|
||||||
return new SheetIterator(workbookPart);
|
return new SheetIterator(workbookPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,8 +265,24 @@ public class XSSFReader {
|
|||||||
*
|
*
|
||||||
* @throws InvalidFormatException if the sheet data format is invalid
|
* @throws InvalidFormatException if the sheet data format is invalid
|
||||||
* @throws IOException if there is an I/O issue reading the data
|
* @throws IOException if there is an I/O issue reading the data
|
||||||
|
* @see #getSheetIterator()
|
||||||
*/
|
*/
|
||||||
public Iterator<InputStream> getSheetsData() throws IOException, InvalidFormatException {
|
public Iterator<InputStream> getSheetsData() throws IOException, InvalidFormatException {
|
||||||
|
return getSheetIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an Iterator which will let you get at all the
|
||||||
|
* different Sheets in turn.
|
||||||
|
* Each sheet's InputStream is only opened when fetched
|
||||||
|
* from the Iterator. It's up to you to close the
|
||||||
|
* InputStreams when done with each one.
|
||||||
|
*
|
||||||
|
* @throws InvalidFormatException if the sheet data format is invalid
|
||||||
|
* @throws IOException if there is an I/O issue reading the data
|
||||||
|
* @since POI 5.3.1
|
||||||
|
*/
|
||||||
|
public SheetIterator getSheetIterator() throws IOException, InvalidFormatException {
|
||||||
return new SheetIterator(workbookPart);
|
return new SheetIterator(workbookPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ public final class TestXSSFReader {
|
|||||||
XSSFReader r = new XSSFReader(pkg);
|
XSSFReader r = new XSSFReader(pkg);
|
||||||
|
|
||||||
String[] sheetNames = {"Sheet4", "Sheet2", "Sheet3", "Sheet1"};
|
String[] sheetNames = {"Sheet4", "Sheet2", "Sheet3", "Sheet1"};
|
||||||
XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
|
XSSFReader.SheetIterator it = r.getSheetIterator();
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user