Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shape强转成XSSFPicture BUG #83

Open
lihanxie opened this issue Apr 20, 2023 · 0 comments
Open

Shape强转成XSSFPicture BUG #83

lihanxie opened this issue Apr 20, 2023 · 0 comments

Comments

@lihanxie
Copy link

org.apache.poi.xssf.usermodel.XSSFSimpleShape cannot be cast to org.apache.poi.xssf.usermodel.XSSFPicture

at org.jeecgframework.poi.util.PoiPublicUtil.getSheetPictrues07(PoiPublicUtil.java:286)
at org.jeecgframework.poi.excel.imports.ExcelImportServer.importExcelByIs(ExcelImportServer.java:405)
at org.jeecgframework.poi.excel.ExcelImportUtil.importExcel(ExcelImportUtil.java:85)

是否可以修改如下:
/**
* 获取Excel2007图片
*
* @param sheet
* 当前sheet对象
* @param workbook
* 工作簿对象
* @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
*/
public static Map<String, PictureData> getSheetPictrues07(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 shapes = drawing.getShapes();
for (XSSFShape shape : shapes) {
if (shape instanceof XSSFPicture) {
XSSFPicture pic = (XSSFPicture) shape;
XSSFClientAnchor anchor = pic.getPreferredSize();
CTMarker ctMarker = anchor.getFrom();
String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
sheetIndexPicMap.put(picIndex, pic.getPictureData());
}
}
}
}
return sheetIndexPicMap;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant