diff --git a/src/main/java/com/github/pjfanning/xlsx/impl/StreamingWorkbookReader.java b/src/main/java/com/github/pjfanning/xlsx/impl/StreamingWorkbookReader.java index 057156e0..ab7352ca 100644 --- a/src/main/java/com/github/pjfanning/xlsx/impl/StreamingWorkbookReader.java +++ b/src/main/java/com/github/pjfanning/xlsx/impl/StreamingWorkbookReader.java @@ -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; @@ -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) { diff --git a/src/main/java/com/github/pjfanning/xlsx/impl/ooxml/OoxmlReader.java b/src/main/java/com/github/pjfanning/xlsx/impl/ooxml/OoxmlReader.java index 57aafef9..f2c066c5 100644 --- a/src/main/java/com/github/pjfanning/xlsx/impl/ooxml/OoxmlReader.java +++ b/src/main/java/com/github/pjfanning/xlsx/impl/ooxml/OoxmlReader.java @@ -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( @@ -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 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 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() {