/**
* 获取Excel2007图片
* @param sheetNum 当前sheet编号
* @param sheet 当前sheet对象
* @param workbook 工作簿对象
* @return Map key:图片单元格索引(0_1_1)String,value:图片流PictureData
*/
public static Map<String, PictureData> getSheetPictrues07(int sheetNum,XSSFSheet sheet, XSSFWorkbook workbook) {
Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
for (POIXMLDocumentPart dr : sheet.getRelations()) {
if (dr instanceof XSSFDrawing) {
XSSFDrawing drawing = (XSSFDrawing) dr;
List<XSSFShape> shapes = drawing.getShapes();
for (XSSFShape shape : shapes) {
XSSFPicture pic = (XSSFPicture) shape;
Dimension d = pic.getImageDimension();
//解决图片空指针报错问题 lig 2021-06-03
XSSFClientAnchor anchor = (XSSFClientAnchor) shape.getAnchor();
// XSSFClientAnchor anchor = pic.getPreferredSize();
CTMarker ctMarker = anchor.getFrom();
// String picIndex = String.valueOf(sheetNum) + "_"
// + ctMarker.getRow() + "_" + ctMarker.getCol();
//解决用户头像格式错误 lig 2021-06-03
String picIndex = "ID"+String.valueOf(ctMarker.getRow()) + "-" + anchor.getCol1();
sheetIndexPicMap.put(picIndex, pic.getPictureData());
}
}
}
return sheetIndexPicMap;
}
jxls-poi pic.getPreferredSize() 空指针异常,excel图片获取异常(已解决)
最新推荐文章于 2024-08-23 21:23:28 发布