for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) { HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor(); if (shape instanceof HSSFPicture) { HSSFPicture pic = (HSSFPicture) shape; System.out.println("第几列:" + anchor.getCol1()); System.out.println("第几行:" + anchor.getRow1()); System.out.println(pic.getPictureData().suggestFileExtension()); System.out.println(pic.getPictureData().getMimeType()); InputStream inputStream = new ByteArrayInputStream(pic.getPictureData().getData()); ByteArrayOutputStream outStream = new ByteArrayOutputStream();//创建一个Buffer字符串 byte[] buffer = new byte[1024]; //每次读取的字符串长度,如果为-1,代表全部读取完毕int len = 0; int len = 0; //使用一个输入流从buffer里把数据读取出来 while( ( len=inputStream.read(buffer)) != -1 ){ outStream.write(buffer,0,len); } inputStream.close(); byte[] date = outStream.toByteArray(); File imageFile = new File("D://test1.jpg"); if (!imageFile.exists()) { imageFile.mkdirs();// 创建文件根目录 } OutputStream fileOutputStream = new FileOutputStream(imageFile); fileOutputStream.write(date); fileOutputStream.close(); } }
Java poi Excel获取单元格外图片
最新推荐文章于 2024-03-20 09:46:44 发布