Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
david5w opened this issue Mar 9, 2021 · 5 comments
Open

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

david5w opened this issue Mar 9, 2021 · 5 comments

Comments

@david5w
Copy link

david5w commented Mar 9, 2021

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)
<...>

@pjfanning
Copy link
Owner

This is not an issue in this library. The exception happens in java.util.zip.ZipFile

@david5w
Copy link
Author

david5w commented Mar 10, 2021 via email

@pjfanning
Copy link
Owner

pjfanning commented Mar 15, 2022

#103 (comment) - similar use case and my answer is applicable here too

@oviniciuslara
Copy link

@david5w did you find a way to fit your use case?

@david5w
Copy link
Author

david5w commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants