@Override public boolean equals(Object o) { if (o == null || !(o instanceof XSSFClientAnchor)) return false; XSSFClientAnchor anchor = (XSSFClientAnchor) o; return getDx1() == anchor.getDx1() && getDx2() == anchor.getDx2() && getDy1() == anchor.getDy1() && getDy2() == anchor.getDy2() && getCol1() == anchor.getCol1() && getCol2() == anchor.getCol2() && getRow1() == anchor.getRow1() && getRow2() == anchor.getRow2() ; }
int dy2Pixels = ca.getDy2() / Units.EMU_PER_PIXEL; String position = ca.getCol1() + ", " + dx1Pixels + ", " + ca.getRow1() + ", " + dy1Pixels + ", " + ca .getCol2() + ", " + dx2Pixels + ", " + ca.getRow2() + ", " + dy2Pixels; vmlShape.getClientDataArray(0).setAnchorArray(0, position);
int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1()); int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1());
/** * Reset the image to the original size. * <p> * Please note, that this method works correctly only for workbooks * with the default font size (Calibri 11pt for .xlsx). * 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. */ @Override public void resize(double scale){ XSSFClientAnchor anchor = getClientAnchor(); XSSFClientAnchor pref = getPreferredSize(scale); if (anchor == null || pref == null) { logger.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call"); return; } int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1()); int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1()); anchor.setCol2(col2); anchor.setDx1(0); anchor.setDx2(pref.getDx2()); anchor.setRow2(row2); anchor.setDy1(0); anchor.setDy2(pref.getDy2()); }
private CTTransform2D createXfrm(XSSFClientAnchor anchor) { CTTransform2D xfrm = CTTransform2D.Factory.newInstance(); CTPoint2D off = xfrm.addNewOff(); off.setX(anchor.getDx1()); off.setY(anchor.getDy1()); XSSFSheet sheet = getSheet(); double widthPx = 0; for (int col = anchor.getCol1(); col < anchor.getCol2(); col++) { widthPx += sheet.getColumnWidthInPixels(col); } double heightPx = 0; for (int row = anchor.getRow1(); row < anchor.getRow2(); row++) { heightPx += ImageUtils.getRowHeightInPixels(sheet, row); } long width = Units.pixelToEMU((int) widthPx); long height = Units.pixelToEMU((int) heightPx); CTPositiveSize2D ext = xfrm.addNewExt(); ext.setCx(width - anchor.getDx1() + anchor.getDx2()); ext.setCy(height - anchor.getDy1() + anchor.getDy2()); // TODO: handle vflip/hflip return xfrm; }
XSSFDrawing dp = wb.getSheetAt(0).createDrawingPatriarch(); List<XSSFShape> pics = dp.getShapes(); XSSFPicture inpPic = (XSSFPicture)pics.get(0); XSSFClientAnchor clientAnchor = inpPic.getClientAnchor(); System.out.println("col1: " + clientAnchor.getCol1() + ", col2: " + clientAnchor.getCol2() + ", row1: " + clientAnchor.getRow1() + ", row2: " + clientAnchor.getRow2()); System.out.println("x1: " + clientAnchor.getDx1() + ", x2: " + clientAnchor.getDx2() + ", y1: " + clientAnchor.getDy1() + ", y2: " + clientAnchor.getDy2());
@Override public boolean equals(Object o) { if (o == null || !(o instanceof XSSFClientAnchor)) return false; XSSFClientAnchor anchor = (XSSFClientAnchor) o; return getDx1() == anchor.getDx1() && getDx2() == anchor.getDx2() && getDy1() == anchor.getDy1() && getDy2() == anchor.getDy2() && getCol1() == anchor.getCol1() && getCol2() == anchor.getCol2() && getRow1() == anchor.getRow1() && getRow2() == anchor.getRow2() ; }
int dy2Pixels = ca.getDy2() / Units.EMU_PER_PIXEL; String position = ca.getCol1() + ", " + dx1Pixels + ", " + ca.getRow1() + ", " + dy1Pixels + ", " + ca .getCol2() + ", " + dx2Pixels + ", " + ca.getRow2() + ", " + dy2Pixels; vmlShape.getClientDataArray(0).setAnchorArray(0, position);
/** * Reset the image to the original size. * <p> * Please note, that this method works correctly only for workbooks * with the default font size (Calibri 11pt for .xlsx). * 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){ XSSFClientAnchor anchor = (XSSFClientAnchor)getAnchor(); XSSFClientAnchor pref = getPreferredSize(scale); int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1()); int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1()); anchor.setCol2(col2); anchor.setDx1(0); anchor.setDx2(pref.getDx2()); anchor.setRow2(row2); anchor.setDy1(0); anchor.setDy2(pref.getDy2()); }
int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1()); int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1());
/** * Creates a comment. * @param anchor the client anchor describes how this comment is attached * to the sheet. * @return the newly created comment. */ public XSSFComment createCellComment(ClientAnchor anchor) { XSSFClientAnchor ca = (XSSFClientAnchor)anchor; XSSFSheet sheet = (XSSFSheet)getParent(); //create comments and vmlDrawing parts if they don't exist CommentsTable comments = sheet.getCommentsTable(true); XSSFVMLDrawing vml = sheet.getVMLDrawing(true); schemasMicrosoftComVml.CTShape vmlShape = vml.newCommentShape(); if(ca.isSet()){ String position = ca.getCol1() + ", 0, " + ca.getRow1() + ", 0, " + ca.getCol2() + ", 0, " + ca.getRow2() + ", 0"; vmlShape.getClientDataArray(0).setAnchorArray(0, position); } XSSFComment shape = new XSSFComment(comments, comments.newComment(), vmlShape); shape.setColumn(ca.getCol1()); shape.setRow(ca.getRow1()); return shape; }
/** * Reset the image to the original size. * <p> * Please note, that this method works correctly only for workbooks * with the default font size (Calibri 11pt for .xlsx). * 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. */ @Override public void resize(double scale){ XSSFClientAnchor anchor = getClientAnchor(); XSSFClientAnchor pref = getPreferredSize(scale); if (anchor == null || pref == null) { logger.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call"); return; } int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1()); int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1()); anchor.setCol2(col2); anchor.setDx1(0); anchor.setDx2(pref.getDx2()); anchor.setRow2(row2); anchor.setDy1(0); anchor.setDy2(pref.getDy2()); }
private CTTransform2D createXfrm(XSSFClientAnchor anchor) { CTTransform2D xfrm = CTTransform2D.Factory.newInstance(); CTPoint2D off = xfrm.addNewOff(); off.setX(anchor.getDx1()); off.setY(anchor.getDy1()); XSSFSheet sheet = getSheet(); double widthPx = 0; for (int col = anchor.getCol1(); col < anchor.getCol2(); col++) { widthPx += sheet.getColumnWidthInPixels(col); } double heightPx = 0; for (int row = anchor.getRow1(); row < anchor.getRow2(); row++) { heightPx += ImageUtils.getRowHeightInPixels(sheet, row); } long width = Units.pixelToEMU((int) widthPx); long height = Units.pixelToEMU((int) heightPx); CTPositiveSize2D ext = xfrm.addNewExt(); ext.setCx(width - anchor.getDx1() + anchor.getDx2()); ext.setCy(height - anchor.getDy1() + anchor.getDy2()); // TODO: handle vflip/hflip return xfrm; }