Skip to content

Commit

Permalink
preserve InvalidFormatException
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Jan 19, 2024
1 parent ac1e622 commit f9dd70f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.github.pjfanning.xlsx.impl.ooxml.OoxmlReader;
import org.apache.commons.io.IOUtils;
import org.apache.poi.UnsupportedFileFormatException;
import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.ooxml.POIXMLProperties;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
Expand Down Expand Up @@ -163,7 +164,8 @@ private OPCPackage decryptWorkbook(POIFSFileSystem poifs) throws IOException, Ge
return OPCPackage.open(d.getDataStream(poifs));
}

private void loadPackage(OPCPackage pkg) throws IOException, OpenXML4JException, SAXException, XMLStreamException {
private void loadPackage(OPCPackage pkg)
throws IOException, OpenXML4JException, SAXException, XMLStreamException, POIXMLException {
strictFormat = pkg.isStrictOoxmlFormat();
ooxmlReader = new OoxmlReader(builder, pkg, strictFormat);
if (strictFormat) {
Expand Down
33 changes: 15 additions & 18 deletions src/main/java/com/github/pjfanning/xlsx/impl/ooxml/OoxmlReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class OoxmlReader extends XSSFReader {
@Internal
public OoxmlReader(StreamingReader.Builder builder,
OPCPackage pkg, boolean strictOoxmlChecksNeeded)
throws IOException, OpenXML4JException, POIXMLException {
throws IOException, OpenXML4JException, InvalidFormatException, POIXMLException {
super(pkg, true);

PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
Expand Down Expand Up @@ -187,33 +187,30 @@ static class OoxmlSheetReader {
*
* @param wb package part holding workbook.xml
* @throws IOException if reading the data from the package fails
* @throws POIXMLException if the package data is invalid
* @throws InvalidFormatException if the package data is invalid
* @throws RuntimeException the underlying POI code can throw other RuntimeExceptions
*/
OoxmlSheetReader(final StreamingReader.Builder builder,
final PackagePart wb, final boolean strictOoxmlChecksNeeded)
throws IOException, POIXMLException {
throws IOException, InvalidFormatException {
this.builder = builder;
this.strictOoxmlChecksNeeded = strictOoxmlChecksNeeded;
/*
* The order of sheets is defined by the order of CTSheet elements in workbook.xml
*/
try {
//step 1. Map sheet's relationship Id and the corresponding PackagePart
sheetMap = new HashMap<>();
OPCPackage pkg = wb.getPackage();
Set<String> worksheetRels = getSheetRelationships();
for (PackageRelationship rel : wb.getRelationships()) {
String relType = rel.getRelationshipType();
if (worksheetRels.contains(relType)) {
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
sheetMap.put(rel.getId(), pkg.getPart(relName));
}
//step 1. Map sheet's relationship Id and the corresponding PackagePart
sheetMap = new HashMap<>();
OPCPackage pkg = wb.getPackage();
Set<String> worksheetRels = getSheetRelationships();
for (PackageRelationship rel : wb.getRelationships()) {
String relType = rel.getRelationshipType();
if (worksheetRels.contains(relType)) {
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
sheetMap.put(rel.getId(), pkg.getPart(relName));
}
//step 2. Read array of CTSheet elements, wrap it in a LinkedList
sheetRefList = createSheetListFromWB(wb);
} catch (InvalidFormatException e) {
throw new POIXMLException(e);
}
//step 2. Read array of CTSheet elements, wrap it in a LinkedList
sheetRefList = createSheetListFromWB(wb);
}

int size() {
Expand Down

0 comments on commit f9dd70f

Please sign in to comment.