/** * Returns the shapes associated with this sheet, * an empty list or null if there is an exception */ public List<XSSFShape> getShapes() { PackagePart sheetPkg = getSheetPart(); List<XSSFShape> shapes = new LinkedList<>(); // Do we have a comments relationship? (Only ever one if so) try { PackageRelationshipCollection drawingsList = sheetPkg.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation()); for (int i = 0; i < drawingsList.size(); i++) { PackageRelationship drawings = drawingsList.getRelationship(i); PackagePartName drawingsName = PackagingURIHelper.createPartName(drawings.getTargetURI()); PackagePart drawingsPart = sheetPkg.getPackage().getPart(drawingsName); if (drawingsPart == null) { //parts can go missing; Excel ignores them silently -- TIKA-2134 LOGGER.log(POILogger.WARN, "Missing drawing: " + drawingsName + ". Skipping it."); continue; } XSSFDrawing drawing = new XSSFDrawing(drawingsPart); shapes.addAll(drawing.getShapes()); } } catch (XmlException|InvalidFormatException|IOException e) { LOGGER.log(POILogger.WARN, e); return null; } return shapes; }
void loadSheets(XSSFReader reader, SharedStringsTable sst, StylesTable stylesTable, int rowCacheSize) throws IOException, InvalidFormatException, XMLStreamException { lookupSheetNames(reader); //Some workbooks have multiple references to the same sheet. Need to filter //them out before creating the XMLEventReader by keeping track of their URIs. //The sheets are listed in order, so we must keep track of insertion order. SheetIterator iter = (SheetIterator) reader.getSheetsData(); Map<URI, InputStream> sheetStreams = new LinkedHashMap<>(); while(iter.hasNext()) { InputStream is = iter.next(); sheetStreams.put(iter.getSheetPart().getPartName().getURI(), is); } //Iterate over the loaded streams int i = 0; for(URI uri : sheetStreams.keySet()) { XMLEventReader parser = StaxHelper.newXMLInputFactory().createXMLEventReader(sheetStreams.get(uri)); sheets.add(new StreamingSheet(sheetProperties.get(i++).get("name"), new StreamingSheetReader(sst, stylesTable, parser, use1904Dates, rowCacheSize))); } }
PackagePart sheetPart = null; try (InputStream stream = iter.next()) { sheetPart = iter.getSheetPart();
PackagePart sheetPart = iter.getSheetPart(); addDrawingHyperLinks(sheetPart); sheetParts.add(sheetPart);
PackagePart sheetPart = null; try (InputStream stream = iter.next()) { sheetPart = iter.getSheetPart();
/** * Returns the shapes associated with this sheet, * an empty list or null if there is an exception */ public List<XSSFShape> getShapes() { PackagePart sheetPkg = getSheetPart(); List<XSSFShape> shapes = new LinkedList<>(); // Do we have a comments relationship? (Only ever one if so) try { PackageRelationshipCollection drawingsList = sheetPkg.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation()); for (int i = 0; i < drawingsList.size(); i++) { PackageRelationship drawings = drawingsList.getRelationship(i); PackagePartName drawingsName = PackagingURIHelper.createPartName(drawings.getTargetURI()); PackagePart drawingsPart = sheetPkg.getPackage().getPart(drawingsName); if (drawingsPart == null) { //parts can go missing; Excel ignores them silently -- TIKA-2134 LOGGER.log(POILogger.WARN, "Missing drawing: " + drawingsName + ". Skipping it."); continue; } XSSFDrawing drawing = new XSSFDrawing(drawingsPart); shapes.addAll(drawing.getShapes()); } } catch (XmlException|InvalidFormatException|IOException e) { LOGGER.log(POILogger.WARN, e); return null; } return shapes; }
/** * Returns the comments associated with this sheet, * or null if there aren't any */ public CommentsTable getSheetComments() { PackagePart sheetPkg = getSheetPart(); // Do we have a comments relationship? (Only ever one if so) try { PackageRelationshipCollection commentsList = sheetPkg.getRelationshipsByType(XSSFRelation.SHEET_COMMENTS.getRelation()); if(commentsList.size() > 0) { PackageRelationship comments = commentsList.getRelationship(0); PackagePartName commentsName = PackagingURIHelper.createPartName(comments.getTargetURI()); PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName); return new CommentsTable(commentsPart, comments); } } catch (InvalidFormatException e) { return null; } catch (IOException e) { return null; } return null; }
/** * Returns the comments associated with this sheet, * or null if there aren't any */ public CommentsTable getSheetComments() { PackagePart sheetPkg = getSheetPart(); // Do we have a comments relationship? (Only ever one if so) try { PackageRelationshipCollection commentsList = sheetPkg.getRelationshipsByType(XSSFRelation.SHEET_COMMENTS.getRelation()); if (commentsList.size() > 0) { PackageRelationship comments = commentsList.getRelationship(0); PackagePartName commentsName = PackagingURIHelper.createPartName(comments.getTargetURI()); PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName); return new CommentsTable(commentsPart); } } catch (InvalidFormatException|IOException e) { LOGGER.log(POILogger.WARN, e); return null; } return null; }
/** * Returns the comments associated with this sheet, * or null if there aren't any */ public CommentsTable getSheetComments() { PackagePart sheetPkg = getSheetPart(); // Do we have a comments relationship? (Only ever one if so) try { PackageRelationshipCollection commentsList = sheetPkg.getRelationshipsByType(XSSFRelation.SHEET_COMMENTS.getRelation()); if (commentsList.size() > 0) { PackageRelationship comments = commentsList.getRelationship(0); PackagePartName commentsName = PackagingURIHelper.createPartName(comments.getTargetURI()); PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName); return new CommentsTable(commentsPart); } } catch (InvalidFormatException|IOException e) { LOGGER.log(POILogger.WARN, e); return null; } return null; }