jxls-poi pic.getPreferredSize() 空指针异常,excel图片获取异常(已解决)

/**
	 * 获取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;
	}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值