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;
}
Aggregations