/** * Returns an iterator over the shapes in this sheet * * @return an iterator over the shapes in this sheet */ @Override public Iterator<XSLFShape> iterator(){ return getShapes().iterator(); }
@SuppressWarnings("WeakerAccess") protected XSLFTextShape getTextShapeByType(Placeholder type){ for(XSLFShape shape : this.getShapes()){ if(shape instanceof XSLFTextShape) { XSLFTextShape txt = (XSLFTextShape)shape; if(txt.getTextType() == type) { return txt; } } } return null; }
/** * Removes all of the elements from this container (optional operation). * The container will be empty after this call returns. */ @Override public void clear() { List<XSLFShape> shapes = new ArrayList<>(getShapes()); for(XSLFShape shape : shapes){ removeShape(shape); } }
@Override public List<List<XSLFTextParagraph>> getTextParagraphs() { List<List<XSLFTextParagraph>> tp = new ArrayList<>(); for (XSLFShape sh : super.getShapes()) { if (sh instanceof XSLFTextShape) { XSLFTextShape txt = (XSLFTextShape)sh; tp.add(txt.getTextParagraphs()); } } return tp; } }
private void wipeAndReinitialize(XSLFSheet src, int offset) { // explicitly initialize drawing and shapes from _spTree _shapes = null; _drawing = null; initDrawingAndShapes(); // placeholders will be implicitly initialized when requested _placeholders = null; // update each shape according to its own additional copy rules List<XSLFShape> tgtShapes = getShapes(); List<XSLFShape> srcShapes = src.getShapes(); for(int i = 0; i < srcShapes.size(); i++){ XSLFShape s1 = srcShapes.get(i); XSLFShape s2 = tgtShapes.get(offset + i); s2.copy(s1); } }
@Override public XSLFTextBox createTextBox(){ XSLFTextBox sh = getDrawing().createTextBox(); getShapes().add(sh); sh.setParent(this); return sh; }
@Override public XSLFAutoShape createAutoShape(){ XSLFAutoShape sh = getDrawing().createAutoShape(); getShapes().add(sh); sh.setParent(this); return sh; }
public XSLFTable createTable(){ XSLFTable sh = getDrawing().createTable(); getShapes().add(sh); sh.setParent(this); return sh; }
@Override public XSLFFreeformShape createFreeform(){ XSLFFreeformShape sh = getDrawing().createFreeform(); getShapes().add(sh); sh.setParent(this); return sh; }
@Override public XSLFConnectorShape createConnector(){ XSLFConnectorShape sh = getDrawing().createConnector(); getShapes().add(sh); sh.setParent(this); return sh; }
@Override public XSLFGroupShape createGroup(){ XSLFGroupShape sh = getDrawing().createGroup(); getShapes().add(sh); sh.setParent(this); return sh; }
@Override public XSLFTable createTable(int numRows, int numCols){ if (numRows < 1 || numCols < 1) { throw new IllegalArgumentException("numRows and numCols must be greater than 0"); } XSLFTable sh = getDrawing().createTable(); getShapes().add(sh); sh.setParent(this); for (int r=0; r<numRows; r++) { XSLFTableRow row = sh.addRow(); for (int c=0; c<numCols; c++) { row.addCell(); } } return sh; }
private void initPlaceholders() { if(_placeholders == null) { _placeholders = new ArrayList<>(); _placeholderByIdMap = new HashMap<>(); _placeholderByTypeMap = new HashMap<>(); for(final XSLFShape sh : getShapes()){ if(sh instanceof XSLFTextShape){ final XSLFTextShape sShape = (XSLFTextShape)sh; final CTPlaceholder ph = sShape.getPlaceholderDetails().getCTPlaceholder(false); if(ph != null) { _placeholders.add(sShape); if(ph.isSetIdx()) { int idx = (int)ph.getIdx(); _placeholderByIdMap.put(idx, sShape); } if(ph.isSetType()){ _placeholderByTypeMap.put(ph.getType().intValue(), sShape); } } } } } }
@Override public XSLFPictureShape createPicture(PictureData pictureData){ if (!(pictureData instanceof XSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData"); } RelationPart rp = addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData); XSLFPictureShape sh = getDrawing().createPicture(rp.getRelationship().getId()); new DrawPictureShape(sh).resize(); getShapes().add(sh); sh.setParent(this); return sh; }
throw new IllegalArgumentException("Unsupported shape: " + xShape); return getShapes().remove(xShape);
@Override public XSLFObjectShape createOleShape(PictureData pictureData) { if (!(pictureData instanceof XSLFPictureData)) { throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData"); } RelationPart rp = addRelation(null, XSLFRelation.IMAGES, (XSLFPictureData)pictureData); XSLFObjectShape sh = getDrawing().createOleShape(rp.getRelationship().getId()); CTOleObject oleObj = sh.getCTOleObject(); Dimension dim = pictureData.getImageDimension(); oleObj.setImgW(Units.toEMU(dim.getWidth())); oleObj.setImgH(Units.toEMU(dim.getHeight())); getShapes().add(sh); sh.setParent(this); return sh; }
/** * Helper method for sheet and group shapes * * @param pictureShape the picture shapes whose relation is to be removed, * only if there are no more relations on its sheet to that picture */ void removePictureRelation(XSLFPictureShape pictureShape) { int numberOfRelations = 0; String targetBlipId = pictureShape.getBlipId(); for (XSLFShape shape : pictureShape.getSheet().getShapes()) { if (shape instanceof XSLFPictureShape) { XSLFPictureShape currentPictureShape = ((XSLFPictureShape) shape); String currentBlipId = currentPictureShape.getBlipId(); if (currentBlipId != null && currentBlipId.equals(targetBlipId)) { numberOfRelations++; } } } if (numberOfRelations <= 1) { removeRelation(pictureShape.getBlipId()); } }
/** * Append content to this sheet. * * @param src the source sheet * @return modified <code>this</code>. */ @SuppressWarnings("unused") public XSLFSheet appendContent(XSLFSheet src){ int numShapes = getShapes().size(); CTGroupShape spTree = getSpTree(); CTGroupShape srcTree = src.getSpTree(); for(XmlObject ch : srcTree.selectPath("*")){ if(ch instanceof CTShape){ // simple shape spTree.addNewSp().set(ch.copy()); } else if (ch instanceof CTGroupShape){ spTree.addNewGrpSp().set(ch.copy()); } else if (ch instanceof CTConnector){ spTree.addNewCxnSp().set(ch.copy()); } else if (ch instanceof CTPicture){ spTree.addNewPic().set(ch.copy()); } else if (ch instanceof CTGraphicalObjectFrame){ spTree.addNewGraphicFrame().set(ch.copy()); } } wipeAndReinitialize(src, numShapes); return this; }
extractContent(slideMaster.getShapes(), true, xhtml, null);
@Override public XSLFFreeformShape createFreeform(){ XSLFFreeformShape sh = getDrawing().createFreeform(); getShapes().add(sh); sh.setParent(this); return sh; }