EXCEL圖片導出

public void setPicture1(){
         String str ="E:/a.jpg";
         String str1 ="E:/b.jpg";
          FileOutputStream fileOut = null;       
          BufferedImage bufferImg = null; 
          BufferedImage bufferImg2 = null; 
         
          //先把讀
          try{
              ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
              ByteArrayOutputStream byteArrayOut1 = new ByteArrayOutputStream(); 
              bufferImg = ImageIO.read(new File(str));    
              ImageIO.write(bufferImg, "jpg", byteArrayOut); 
              bufferImg2 = ImageIO.read(new File(str1));    
              ImageIO.write(bufferImg2, "jpg", byteArrayOut1);  
              //畫圖的頂級管理器,一個sheet只能獲取一個(必定要注意這點)  
              HSSFPatriarch patriarch = this.sheet.createDrawingPatriarch();  
            //anchor主要用於設置圖片的屬性 
              HSSFClientAnchor  anchor = new HSSFClientAnchor(50, 50, 200, 200,(short) 4, 7, (short) 5, 7);
              HSSFClientAnchor  anchor2 = new HSSFClientAnchor(50, 50, 200, 200,(short) 4, 8, (short) 5, 8);
               anchor.setAnchorType(3);
              //插入圖片    
              patriarch.createPicture(anchor, this.workbook.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
              patriarch.createPicture(anchor2, this.workbook.addPicture(byteArrayOut1.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
                // 寫入excel文件     
                      
          } catch (Exception e) {
              e.printStackTrace();     
              }finally{       
                  if(fileOut != null){     
                      try {            
                          fileOut.close();        
                          } catch (IOException e) {          
                              e.printStackTrace();        
                              } 
              }
          }
        
    }this

相關文章
相關標籤/搜索