| | |
| | | //存储图片信息及所在分页 |
| | | Map<Integer,PictureData> pictureDataMap = new HashMap<>(); |
| | | if(excelType == 1){ //.xls |
| | | List<HSSFShape> children = ((HSSFSheet) sheet).getDrawingPatriarch().getChildren(); |
| | | for (HSSFShape child : children) { |
| | | HSSFPicture picture = (HSSFPicture)child; |
| | | HSSFPictureData pictureData = picture.getPictureData(); |
| | | HSSFClientAnchor anchor = (HSSFClientAnchor) child.getAnchor(); |
| | | //行,不能跨行; |
| | | int row1 = anchor.getRow1(); |
| | | int row2 = anchor.getRow2(); |
| | | if(row1 == row2){ |
| | | //不跨行,有效 |
| | | pictureDataMap.put(row1,pictureData); |
| | | HSSFPatriarch drawingPatriarch = ((HSSFSheet) sheet).getDrawingPatriarch(); |
| | | if(drawingPatriarch!=null) { |
| | | List<HSSFShape> children = drawingPatriarch.getChildren(); |
| | | for (HSSFShape child : children) { |
| | | HSSFPicture picture = (HSSFPicture) child; |
| | | HSSFPictureData pictureData = picture.getPictureData(); |
| | | HSSFClientAnchor anchor = (HSSFClientAnchor) child.getAnchor(); |
| | | //行,不能跨行; |
| | | int row1 = anchor.getRow1(); |
| | | int row2 = anchor.getRow2(); |
| | | if (row1 == row2) { |
| | | //不跨行,有效 |
| | | pictureDataMap.put(row1, pictureData); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else if(excelType == 2){ //.xlsx |
| | | List<XSSFShape> children = ((XSSFSheet) sheet).getDrawingPatriarch().getShapes(); |
| | | for (XSSFShape child : children) { |
| | | XSSFPicture picture = (XSSFPicture)child; |
| | | XSSFPictureData pictureData = picture.getPictureData(); |
| | | XSSFClientAnchor anchor = (XSSFClientAnchor) child.getAnchor(); |
| | | //行,不能跨行; |
| | | int row1 = anchor.getRow1(); |
| | | int row2 = anchor.getRow2(); |
| | | if(row1 == row2){ |
| | | //不跨行,有效 |
| | | pictureDataMap.put(row1,pictureData); |
| | | XSSFDrawing drawingPatriarch = ((XSSFSheet) sheet).getDrawingPatriarch(); |
| | | if(drawingPatriarch!=null) { |
| | | List<XSSFShape> children = drawingPatriarch.getShapes(); |
| | | for (XSSFShape child : children) { |
| | | XSSFPicture picture = (XSSFPicture) child; |
| | | XSSFPictureData pictureData = picture.getPictureData(); |
| | | XSSFClientAnchor anchor = (XSSFClientAnchor) child.getAnchor(); |
| | | //行,不能跨行; |
| | | int row1 = anchor.getRow1(); |
| | | int row2 = anchor.getRow2(); |
| | | if (row1 == row2) { |
| | | //不跨行,有效 |
| | | pictureDataMap.put(row1, pictureData); |
| | | } |
| | | } |
| | | } |
| | | } |