org.apache.poi.hssf.usermodel.HSSFWorkbook.getAllPictures()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(542)

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

HSSFWorkbook.getAllPictures介绍

[英]Gets all pictures from the Workbook.
[中]获取工作簿中的所有图片。

代码示例

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

/**
 * 获取XLS工作簿指定sheet中图片列表
 * 
 * @param workbook 工作簿{@link Workbook}
 * @param sheetIndex sheet的索引
 * @return 图片映射,键格式:行_列,值:{@link PictureData}
 */
private static Map<String, PictureData> getPicMapXls(HSSFWorkbook workbook, int sheetIndex) {
  final Map<String, PictureData> picMap = new HashMap<>();
  final List<HSSFPictureData> pictures = workbook.getAllPictures();
  if (CollectionUtil.isNotEmpty(pictures)) {
    final HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
    HSSFClientAnchor anchor;
    int pictureIndex;
    for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
      if (shape instanceof HSSFPicture) {
        pictureIndex = ((HSSFPicture) shape).getPictureIndex() - 1;
        anchor = (HSSFClientAnchor) shape.getAnchor();
        picMap.put(StrUtil.format("{}_{}", anchor.getRow1(), anchor.getCol1()), pictures.get(pictureIndex));
      }
    }
  }
  return picMap;
}

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

/**
 * 获取XLS工作簿指定sheet中图片列表
 * 
 * @param workbook 工作簿{@link Workbook}
 * @param sheetIndex sheet的索引
 * @return 图片映射,键格式:行_列,值:{@link PictureData}
 */
private static Map<String, PictureData> getPicMapXls(HSSFWorkbook workbook, int sheetIndex) {
  final Map<String, PictureData> picMap = new HashMap<>();
  final List<HSSFPictureData> pictures = workbook.getAllPictures();
  if (CollectionUtil.isNotEmpty(pictures)) {
    final HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
    HSSFClientAnchor anchor;
    int pictureIndex;
    for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
      if (shape instanceof HSSFPicture) {
        pictureIndex = ((HSSFPicture) shape).getPictureIndex() - 1;
        anchor = (HSSFClientAnchor) shape.getAnchor();
        picMap.put(StrUtil.format("{}_{}", anchor.getRow1(), anchor.getCol1()), pictures.get(pictureIndex));
      }
    }
  }
  return picMap;
}

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

HSSFPictureData pictData = getSheet().getWorkbook().getAllPictures().get(pictureIndex-1);
switch (pictData.getFormat()) {
  case Workbook.PICTURE_TYPE_WMF:

代码示例来源:origin: stackoverflow.com

POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(anExcelFile));
HSSFWorkbook workbook = new HSSFWorkbook(fs);

List lst = workbook.getAllPictures();
for (Iterator it = lst.iterator(); it.hasNext(); ) {
  PictureData pict = (PictureData)it.next();
  String ext = pict.suggestFileExtension();
  byte[] data = pict.getData();
  if (ext.equals("jpeg")){
   FileOutputStream out = new FileOutputStream("pict.jpg");
   out.write(data);
   out.close();
  }
}

代码示例来源:origin: cuba-platform/yarg

protected void copyPicturesToResultWorkbook() {
  List<HSSFPictureData> allPictures = templateWorkbook.getAllPictures();
  for (HSSFPictureData allPicture : allPictures) {
    int i = resultWorkbook.addPicture(allPicture.getData(), Workbook.PICTURE_TYPE_JPEG);
    orderedPicturesId.add(i);
  }
}

代码示例来源:origin: com.haulmont.yarg/yarg

protected void copyPicturesToResultWorkbook() {
  List<HSSFPictureData> allPictures = templateWorkbook.getAllPictures();
  for (HSSFPictureData allPicture : allPictures) {
    int i = resultWorkbook.addPicture(allPicture.getData(), Workbook.PICTURE_TYPE_JPEG);
    orderedPicturesId.add(i);
  }
}

代码示例来源:origin: cn.afterturn/easypoi-base

/**
 * 获取Excel2003图片
 *
 * @param sheet
 *            当前sheet对象
 * @param workbook
 *            工作簿对象
 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
 */
public static Map<String, PictureData> getSheetPictrues03(HSSFSheet sheet,
                             HSSFWorkbook workbook) {
  Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
  List<HSSFPictureData> pictures = workbook.getAllPictures();
  if (!pictures.isEmpty()) {
    for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
      HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();
      if (shape instanceof HSSFPicture) {
        HSSFPicture pic = (HSSFPicture) shape;
        int pictureIndex = pic.getPictureIndex() - 1;
        HSSFPictureData picData = pictures.get(pictureIndex);
        String picIndex = String.valueOf(anchor.getRow1()) + "_"
                 + String.valueOf(anchor.getCol1());
        sheetIndexPicMap.put(picIndex, picData);
      }
    }
    return sheetIndexPicMap;
  } else {
    return sheetIndexPicMap;
  }
}

代码示例来源:origin: xiaolanglang/easypoi

/**
 * 获取Excel2003图片
 * 
 * @param sheet
 *            当前sheet对象
 * @param workbook
 *            工作簿对象
 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
 */
public static Map<String, PictureData> getSheetPictrues03(HSSFSheet sheet, HSSFWorkbook workbook) {
  Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
  List<HSSFPictureData> pictures = workbook.getAllPictures();
  if (!pictures.isEmpty()) {
    for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
      HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();
      if (shape instanceof HSSFPicture) {
        HSSFPicture pic = (HSSFPicture) shape;
        int pictureIndex = pic.getPictureIndex() - 1;
        HSSFPictureData picData = pictures.get(pictureIndex);
        String picIndex = String.valueOf(anchor.getRow1()) + "_"
                 + String.valueOf(anchor.getCol1());
        sheetIndexPicMap.put(picIndex, picData);
      }
    }
    return sheetIndexPicMap;
  } else {
    return null;
  }
}

代码示例来源:origin: zhangdaiscott/jeasypoi

/**
 * 获取Excel2003图片
 * 
 * @param sheet
 *            当前sheet对象
 * @param workbook
 *            工作簿对象
 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
 */
public static Map<String, PictureData> getSheetPictrues03(HSSFSheet sheet, HSSFWorkbook workbook) {
  Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
  List<HSSFPictureData> pictures = workbook.getAllPictures();
  if (!pictures.isEmpty()) {
    for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
      HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();
      if (shape instanceof HSSFPicture) {
        HSSFPicture pic = (HSSFPicture) shape;
        int pictureIndex = pic.getPictureIndex() - 1;
        HSSFPictureData picData = pictures.get(pictureIndex);
        String picIndex = String.valueOf(anchor.getRow1()) + "_" + String.valueOf(anchor.getCol1());
        sheetIndexPicMap.put(picIndex, picData);
      }
    }
    return sheetIndexPicMap;
  } else {
    return null;
  }
}

代码示例来源:origin: org.jeecg/easypoi-base

/**
 * 获取Excel2003图片
 * 
 * @param sheet
 *            当前sheet对象
 * @param workbook
 *            工作簿对象
 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
 */
public static Map<String, PictureData> getSheetPictrues03(HSSFSheet sheet,
                             HSSFWorkbook workbook) {
  Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
  List<HSSFPictureData> pictures = workbook.getAllPictures();
  if (!pictures.isEmpty()) {
    for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
      HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();
      if (shape instanceof HSSFPicture) {
        HSSFPicture pic = (HSSFPicture) shape;
        int pictureIndex = pic.getPictureIndex() - 1;
        HSSFPictureData picData = pictures.get(pictureIndex);
        String picIndex = String.valueOf(anchor.getRow1()) + "_"
                 + String.valueOf(anchor.getCol1());
        sheetIndexPicMap.put(picIndex, picData);
      }
    }
    return sheetIndexPicMap;
  } else {
    return sheetIndexPicMap;
  }
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 获取XLS工作簿指定sheet中图片列表
 * 
 * @param workbook 工作簿{@link Workbook}
 * @param sheetIndex sheet的索引
 * @return 图片映射,键格式:行_列,值:{@link PictureData}
 */
private static Map<String, PictureData> getPicMapXls(HSSFWorkbook workbook, int sheetIndex) {
  final Map<String, PictureData> picMap = new HashMap<>();
  final List<HSSFPictureData> pictures = workbook.getAllPictures();
  if (CollectionUtil.isNotEmpty(pictures)) {
    final HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
    HSSFClientAnchor anchor;
    int pictureIndex;
    for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
      if (shape instanceof HSSFPicture) {
        pictureIndex = ((HSSFPicture) shape).getPictureIndex() - 1;
        anchor = (HSSFClientAnchor) shape.getAnchor();
        picMap.put(StrUtil.format("{}_{}", anchor.getRow1(), anchor.getCol1()), pictures.get(pictureIndex));
      }
    }
  }
  return picMap;
}

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

HSSFPictureData pictData = getSheet().getWorkbook().getAllPictures().get(pictureIndex-1);
switch (pictData.getFormat()) {
  case Workbook.PICTURE_TYPE_WMF:

相关文章

HSSFWorkbook类方法