public static void createPic() throws IOException {
FileOutputStream fileOut = null;
BufferedImage bufferImg = null;
try {
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
bufferImg = ImageIO.read(ReaderFileUtils.getFile("desktop3.jpg"));
ImageIO.write(bufferImg, "jpg", byteArrayOut);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("pic");
HSSFPatriarch patriarch = sheet1.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 512, 255,
(short) 1, 1, (short) 10, 20);
HSSFClientAnchor anchor1 = new HSSFClientAnchor(0, 0, 512, 255,
(short) 2, 30, (short) 10, 60);
anchor1.setAnchorType(2);
patriarch
.createPicture(anchor, wb.addPicture(
byteArrayOut.toByteArray(),
HSSFWorkbook.PICTURE_TYPE_JPEG));
fileOut = new FileOutputStream("out.xls");
wb.write(fileOut);
fileOut.close();
} catch (IOException io) {
io.printStackTrace();
} finally {
if (fileOut != null) {
try {
fileOut.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
POI 插入图片
最新推荐文章于 2025-01-10 16:28:34 发布