请教:POI能否提取word2007中的图片。能给出实例吗?

解决方案 »

  1.   


    public void extractImage(String wordDocxPath){
    FileInputStream fis=null;
    FileOutputStream fos=null;
    OPCPackage opcPackage=null;
    XWPFDocument xwpfd =null;
    File file=null;
    file=new File(wordDocxPath);

    try {
         String imgPath =file.getParent()+File.separator+"img";
        //载入文档
    fis = new FileInputStream(wordDocxPath);
    opcPackage= POIXMLDocument.openPackage(wordDocxPath);
    xwpfd= new XWPFDocument(opcPackage);
    //建立图片文件目录
    File imgFile = new File(imgPath);
    if(!imgFile.exists()){
    imgFile.mkdir();
    }
    //获取所图片
    //
        List piclist = xwpfd.getAllPictures();
        for(int j = 0; j < piclist.size(); j++){
         XWPFPictureData pic = (XWPFPictureData) piclist.get(j) ;
         //获取图片数据流
         byte[] picbyte = pic.getData();
         //将图片写入本地文件
         fos = new FileOutputStream(imgPath +file.separator+ file.getName()+j +".jpg");
         fos.write(picbyte);
        }
        }
    catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
     } 
      

  2.   

        List piclist = xwpfd.getAllPictures();老出错啊,请指教
      

  3.   

    List piclist = xwpfd.getAllPictures();解析word2007,没有此方法啊,我的jar包。还是有其他的jar包
      

  4.   

     XWPFDocument xwpfd=new XWPFDocument(opcPackage);
    xwpfd.getAllPictures();jar包中没此方法啊。org.apache.poi.xwpf.usermodel中无此方法啊。