Search in sources :

Example 1 with HSSFPictureData

use of org.apache.poi.hssf.usermodel.HSSFPictureData in project hutool by looly.

the class ExcelPicUtil method getPicMapXls.

// -------------------------------------------------------------------------------------------------------------- Private method start
/**
 * 获取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;
}
Also used : HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HashMap(java.util.HashMap) HSSFShape(org.apache.poi.hssf.usermodel.HSSFShape) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFPicture(org.apache.poi.hssf.usermodel.HSSFPicture) HSSFPictureData(org.apache.poi.hssf.usermodel.HSSFPictureData) HSSFPictureData(org.apache.poi.hssf.usermodel.HSSFPictureData) PictureData(org.apache.poi.ss.usermodel.PictureData)

Aggregations

HashMap (java.util.HashMap)1 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)1 HSSFPicture (org.apache.poi.hssf.usermodel.HSSFPicture)1 HSSFPictureData (org.apache.poi.hssf.usermodel.HSSFPictureData)1 HSSFShape (org.apache.poi.hssf.usermodel.HSSFShape)1 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)1 PictureData (org.apache.poi.ss.usermodel.PictureData)1