org.apache.poi.xssf.usermodel.XSSFPicture类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(797)

本文整理了Java中org.apache.poi.xssf.usermodel.XSSFPicture类的一些代码示例,展示了XSSFPicture类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XSSFPicture类的具体详情如下:
包路径:org.apache.poi.xssf.usermodel.XSSFPicture
类名称:XSSFPicture

XSSFPicture介绍

[英]Represents a picture shape in a SpreadsheetML drawing.
[中]表示电子表格ML图形中的图片形状。

代码示例

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Return the dimension of the embedded image in pixel
 *
 * @return image dimension in pixels
 */
public Dimension getImageDimension() {
  XSSFPictureData picData = getPictureData();
  return getImageDimension(picData.getPackagePart(), picData.getPictureType());
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Calculate the preferred size for this picture.
 *
 * @return XSSFClientAnchor with the preferred size for this image
 */
public XSSFClientAnchor getPreferredSize(){
  return getPreferredSize(1);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Creates a picture.
 *
 * @param anchor       the client anchor describes how this picture is attached to the sheet.
 * @param pictureIndex the index of the picture in the workbook collection of pictures,
 *                     {@link XSSFWorkbook#getAllPictures()} .
 * @return the newly created picture shape.
 */
public XSSFPicture createPicture(XSSFClientAnchor anchor, int pictureIndex) {
  PackageRelationship rel = getDrawing().addPictureReference(pictureIndex);
  CTPicture ctShape = ctGroup.addNewPic();
  ctShape.set(XSSFPicture.prototype());
  XSSFPicture shape = new XSSFPicture(getDrawing(), ctShape);
  shape.parent = this;
  shape.anchor = anchor;
  shape.setPictureReference(rel);
  return shape;
}

代码示例来源:origin: looly/hutool

/**
 * 获取XLSX工作簿指定sheet中图片列表
 * 
 * @param workbook 工作簿{@link Workbook}
 * @param sheetIndex sheet的索引
 * @return 图片映射,键格式:行_列,值:{@link PictureData}
 */
private static Map<String, PictureData> getPicMapXlsx(XSSFWorkbook workbook, int sheetIndex) {
  final Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
  final XSSFSheet sheet = workbook.getSheetAt(sheetIndex);
  XSSFDrawing drawing;
  for (POIXMLDocumentPart dr : sheet.getRelations()) {
    if (dr instanceof XSSFDrawing) {
      drawing = (XSSFDrawing) dr;
      final List<XSSFShape> shapes = drawing.getShapes();
      XSSFPicture pic;
      CTMarker ctMarker;
      for (XSSFShape shape : shapes) {
        pic = (XSSFPicture) shape;
        ctMarker = pic.getPreferredSize().getFrom();
        sheetIndexPicMap.put(StrUtil.format("{}_{}", ctMarker.getRow(), ctMarker.getCol()), pic.getPictureData());
      }
    }
  }
  return sheetIndexPicMap;
}
// -------------------------------------------------------------------------------------------------------------- Private method end

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

XSSFClientAnchor anchor = (XSSFClientAnchor)getAnchor();
XSSFPictureData data = getPictureData();
Dimension size = getImageDimension(data.getPackagePart(), data.getPictureType());
double scaledWidth = size.getWidth() * scale;
double scaledHeight = size.getHeight() * scale;
  w += getColumnWidthInPixels(col2);
  if(w > scaledWidth) break;
  col2++;
  double cw = getColumnWidthInPixels(col2 );
  double delta = w - scaledWidth;
  dx2 = (int)(EMU_PER_PIXEL*(cw-delta));
  h += getRowHeightInPixels(row2);
  if(h > scaledHeight) break;
  row2++;
  double ch = getRowHeightInPixels(row2);
  double delta = h - scaledHeight;
  dy2 = (int)(EMU_PER_PIXEL*(ch-delta));

代码示例来源:origin: org.apache.poi/poi-ooxml

XSSFClientAnchor anchor = getClientAnchor();
XSSFClientAnchor pref = getPreferredSize(scaleX,scaleY);
if (anchor == null || pref == null) {
  logger.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call");

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * 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());
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Return picture data for this shape
 *
 * @return picture data for this shape
 */
@Override
public XSSFPictureData getPictureData() {
  return _picture.getPictureData();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

public XSSFDrawing getDrawing() {
  return _picture.getDrawing();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Resize the image proportionally.
 *
 * @see #resize(double, double)
 */
public void resize(double scale) {
  resize(scale, scale);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * @return the anchor that is used by this shape.
 */
@Override
public XSSFClientAnchor getClientAnchor() {
  XSSFAnchor a = getAnchor();
  return (a instanceof XSSFClientAnchor) ? (XSSFClientAnchor)a : null;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Calculate the preferred size for this picture.
 *
 * @param scaleX the amount by which image width is multiplied relative to the original width.
 * @param scaleY the amount by which image height is multiplied relative to the original height.
 * @return XSSFClientAnchor with the preferred size for this image
 */
public XSSFClientAnchor getPreferredSize(double scaleX, double scaleY){
  Dimension dim = ImageUtils.setPreferredSize(this, scaleX, scaleY);
  CTPositiveSize2D size2d =  ctPicture.getSpPr().getXfrm().getExt();
  size2d.setCx((int)dim.getWidth());
  size2d.setCy((int)dim.getHeight());
  return getClientAnchor();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

shape = new XSSFPicture(this, (CTPicture) obj);
} else if (obj instanceof CTConnector) {
  shape = new XSSFConnector(this, (CTConnector) obj);

代码示例来源:origin: org.apache.poi/poi-ooxml

@Override
public Dimension getImageDimension() {
  return _picture.getImageDimension();
}

代码示例来源:origin: looly/hutool

/**
 * 获取XLSX工作簿指定sheet中图片列表
 * 
 * @param workbook 工作簿{@link Workbook}
 * @param sheetIndex sheet的索引
 * @return 图片映射,键格式:行_列,值:{@link PictureData}
 */
private static Map<String, PictureData> getPicMapXlsx(XSSFWorkbook workbook, int sheetIndex) {
  final Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
  final XSSFSheet sheet = workbook.getSheetAt(sheetIndex);
  XSSFDrawing drawing;
  for (POIXMLDocumentPart dr : sheet.getRelations()) {
    if (dr instanceof XSSFDrawing) {
      drawing = (XSSFDrawing) dr;
      final List<XSSFShape> shapes = drawing.getShapes();
      XSSFPicture pic;
      CTMarker ctMarker;
      for (XSSFShape shape : shapes) {
        pic = (XSSFPicture) shape;
        ctMarker = pic.getPreferredSize().getFrom();
        sheetIndexPicMap.put(StrUtil.format("{}_{}", ctMarker.getRow(), ctMarker.getCol()), pic.getPictureData());
      }
    }
  }
  return sheetIndexPicMap;
}
// -------------------------------------------------------------------------------------------------------------- Private method end

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

XSSFClientAnchor anchor = getClientAnchor();
XSSFClientAnchor pref = getPreferredSize(scaleX,scaleY);
if (anchor == null || pref == null) {
  logger.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call");

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Return picture data for this shape
 *
 * @return picture data for this shape
 */
@Override
public XSSFPictureData getPictureData() {
  return _picture.getPictureData();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * @return the sheet which contains the picture shape
 */
@Override
public XSSFSheet getSheet() {
  return (XSSFSheet)getDrawing().getParent();
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Reset the image to the dimension of the embedded image
 *
 * @see #resize(double, double)
 */
public void resize(){
  resize(Double.MAX_VALUE);
}

代码示例来源:origin: org.apache.poi/poi-ooxml

@Override
public XSSFAnchor getAnchor() {
  return _picture.getAnchor();
}

相关文章