/** * Construct a new SheetIterator * * @param wb package part holding workbook.xml */ SheetIterator(PackagePart wb) throws IOException { /* * 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 2. Read array of CTSheet elements, wrap it in a LinkedList //and construct an iterator sheetIterator = createSheetIteratorFromWB(wb); } catch (InvalidFormatException e) { throw new POIXMLException(e); } }
/** * Construct a new SheetIterator * * @param wb package part holding workbook.xml */ SheetIterator(PackagePart wb) throws IOException { /* * 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 2. Read array of CTSheet elements, wrap it in a LinkedList //and construct an iterator sheetIterator = createSheetIteratorFromWB(wb); } catch (InvalidFormatException e) { throw new POIXMLException(e); } }