Skip to content

Reading first row from first sheet before full file available? #38

@david5w

Description

@david5w

Thank you for this library. Is it reasonable to expect this library to enable access to the first row in the first sheet, when the file is not yet completely available (still sequentially arriving)? Based on the nature of the error, it seems like the underlying ZIP might disallow this.

When I try the following, I get the resulting exception.

List<String> list = new LinkedList<String>();
InputStream in = <...>
try (
	Workbook workbook = StreamingReader.builder().open(in)) {
	Sheet sheet = workbook.getSheetAt(0);
	Row r = sheet.getRow(0);
	for (Cell c : r) {
		list.add(c.getStringCellValue());
	}
}

org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file: '<...>.xlsx'
at org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:137)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:252)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:201)
at com.github.pjfanning.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:117)
at com.github.pjfanning.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:93)
at com.github.pjfanning.xlsx.StreamingReader$Builder.open(StreamingReader.java:247)
<...>
Caused by: java.util.zip.ZipException: zip END header not found
at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1585)
at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1439)
at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1448)
at java.base/java.util.zip.ZipFile$Source.(ZipFile.java:1249)
at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1211)
at java.base/java.util.zip.ZipFile$CleanableResource.(ZipFile.java:701)
at java.base/java.util.zip.ZipFile.(ZipFile.java:240)
at java.base/java.util.zip.ZipFile.(ZipFile.java:171)
at java.base/java.util.zip.ZipFile.(ZipFile.java:185)
at org.apache.poi.openxml4j.util.ZipSecureFile.(ZipSecureFile.java:105)
at org.apache.poi.openxml4j.opc.internal.ZipHelper.openZipFile(ZipHelper.java:158)
at org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:135)
<...>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions