/** * @return the anchor that is used by this picture. */ @Override public HSSFClientAnchor getClientAnchor() { HSSFAnchor a = getAnchor(); return (a instanceof HSSFClientAnchor) ? (HSSFClientAnchor)a : null; }
/** * Creates a picture. * * @param anchor the client anchor describes how this group is attached * to the sheet. * @return the newly created shape. */ public HSSFPicture createPicture(HSSFChildAnchor anchor, int pictureIndex) { HSSFPicture shape = new HSSFPicture(this, anchor); shape.setParent(this); shape.setAnchor(anchor); shape.setPictureIndex(pictureIndex); shapes.add(shape); onCreate(shape); EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); if (shape.getAnchor().isHorizontallyFlipped()){ sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); } if (shape.getAnchor().isVerticallyFlipped()){ sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); } return shape; }
/** * @return the anchor that is used by this picture. */ @Override public HSSFClientAnchor getClientAnchor() { HSSFAnchor a = getAnchor(); return (a instanceof HSSFClientAnchor) ? (HSSFClientAnchor)a : null; }
HSSFClientAnchor anchor = (HSSFClientAnchor)getAnchor();
/** * Creates a picture. * * @param anchor the client anchor describes how this group is attached * to the sheet. * @return the newly created shape. */ public HSSFPicture createPicture(HSSFChildAnchor anchor, int pictureIndex) { HSSFPicture shape = new HSSFPicture(this, anchor); shape.setParent(this); shape.setAnchor(anchor); shape.setPictureIndex(pictureIndex); shapes.add(shape); onCreate(shape); EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); if (shape.getAnchor().isHorizontallyFlipped()){ sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); } if (shape.getAnchor().isVerticallyFlipped()){ sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); } return shape; }
/** * Creates a picture. * * @param anchor the client anchor describes how this group is attached * to the sheet. * @return the newly created shape. */ public HSSFPicture createPicture(HSSFChildAnchor anchor, int pictureIndex) { HSSFPicture shape = new HSSFPicture(this, anchor); shape.setParent(this); shape.setAnchor(anchor); shape.setPictureIndex(pictureIndex); shapes.add(shape); onCreate(shape); EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); if (shape.getAnchor().isHorizontallyFlipped()){ sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); } if (shape.getAnchor().isVerticallyFlipped()){ sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); } return shape; }
int idColumn = ...; int pictureColumn = ...; HSSFSheet sheet = ...; for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) { if (shape instanceof HSSFPicture) { HSSFPicture picture = (HSSFPicture) shape; HSSFClientAnchor anchor = (HSSFClientAnchor) picture.getAnchor(); // Ensure to use only relevant pictures if (anchor.getCol1() == pictureColumn) { // Use the row from the anchor HSSFRow pictureRow = sheet.getRow(anchor.getRow1()); if (pictureRow != null) { HSSFCell idCell = pictureRow.getCell(idColumn); if (idCell != null) { long employeeId = (long) idCell.getNumericCellValue(); myUserService.updatePortrait(employeeId, picture.getData()); } } } } }
HSSFClientAnchor anchor = (HSSFClientAnchor)getAnchor();
/** * Resize the image * <p> * Please note, that this method works correctly only for workbooks * with default font size (Arial 10pt for .xls). * If the default font is changed the resized image can be streched vertically or horizontally. * </p> * * @param scale the amount by which image dimensions are multiplied relative to the original size. * <code>resize(1.0)</code> sets the original size, <code>resize(0.5)</code> resize to 50% of the original, * <code>resize(2.0)</code> resizes to 200% of the original. */ public void resize(double scale){ HSSFClientAnchor anchor = (HSSFClientAnchor)getAnchor(); anchor.setAnchorType(2); HSSFClientAnchor pref = getPreferredSize(scale); int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1()); int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1()); anchor.setCol2((short)col2); anchor.setDx1(0); anchor.setDx2(pref.getDx2()); anchor.setRow2(row2); anchor.setDy1(0); anchor.setDy2(pref.getDy2()); }
/** * Resize the image * <p> * Please note, that this method works correctly only for workbooks * with default font size (Arial 10pt for .xls). * If the default font is changed the resized image can be streched vertically or horizontally. * </p> * * @param scale the amount by which image dimensions are multiplied relative to the original size. * <code>resize(1.0)</code> sets the original size, <code>resize(0.5)</code> resize to 50% of the original, * <code>resize(2.0)</code> resizes to 200% of the original. */ public void resize(double scale){ HSSFClientAnchor anchor = (HSSFClientAnchor)getAnchor(); anchor.setAnchorType(2); HSSFClientAnchor pref = getPreferredSize(scale); int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1()); int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1()); anchor.setCol2((short)col2); anchor.setDx1(0); anchor.setDx2(pref.getDx2()); anchor.setRow2(row2); anchor.setDy1(0); anchor.setDy2(pref.getDy2()); }
HSSFAnchor userAnchor = shape.getAnchor(); if (userAnchor.isHorizontallyFlipped()) sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
HSSFAnchor userAnchor = shape.getAnchor(); if (userAnchor.isHorizontallyFlipped()) sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);