public static void main(String[] args) {
try {
InputStream inp = new FileInputStream("workbook.xlsx");
Workbook wb = WorkbookFactory.create(inp);
XSSFSheet sheet1 = (XSSFSheet)wb.getSheetAt(0);
//returns the existing SpreadsheetDrawingML from the sheet, or creates a new one
XSSFDrawing drawing = sheet1.createDrawingPatriarch();
//loop through all of the shapes in the drawing area
for(XSSFShape shape : drawing.getShapes()){
if(shape instanceof Picture){
//convert the shape into a picture
XSSFPicture picture = (XSSFPicture)shape;
//your logic here
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
# 1 楼答案
我不认为有像
getAllPictures()
这样简单的东西可以用于单独的纸张。一种解决方案是这样做(假设您使用的是XSSF):一般的想法是,我们使用
createDrawingPatriarch()
从工作表中检索现有的电子表格ML图形然后,我们可以使用
getShapes()
检索表中包含的每个形状# 2 楼答案
由于您已经开始使用SS公共接口,您可能希望有一个在两种API中都能工作的解决方案。不幸的是,DrawingPatrich还没有完全普及: