首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

POI 安插图片

2012-10-28 
POI 插入图片public static void createPic() throws IOException {FileOutputStream fileOut nullBuff

POI 插入图片

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 blocke.printStackTrace();}}}}
?

热点排行