就是读取WORD的时候,,,WORD里面的那些例如数学公式,,,会变成一个WMF图片... 直接用原来的POI的图片读取方法...是读取不了这个WMF图片的,,生成了一个没用的文件.. 后来我自己用基本的IO流(但是得到图片的字节数组的方法还是用POI的)生成了一个WMF图片,,可以用图片浏览器浏 览...但是无法在html页面上面显示.. 
而且一个本来可以在html页面上面显示的WMF图片, 经过了POI的读取之后, 也是可以用图片浏览器浏览, 但是在HTML 页面上显示的时候还是显示不了, 一个X... 有没有人知道大概是怎么回事??? 

解决方案 »

  1.   


    /**
      * 将图片导入到特定的文件夹下面
      * 
      * @param directory : WEB应用当前的路径+存放图片的路径
      * @throws IOException
      */
     public  void extractImagesIntoDirectory( String directory ) throws IOException {  PicturesTable pTable = msWord.getPicturesTable();
     int numCharacterRuns = msWord.getRange().numCharacterRuns();  for (int i = 0; i < numCharacterRuns; i++) {
     CharacterRun characterRun = msWord.getRange().getCharacterRun(i);
     if (pTable.hasPicture(characterRun)) {
     Picture pic = pTable.extractPicture(characterRun, true);
     String extName = pic.suggestFileExtension();
     File f = new File( directory + "/" + folderName );
     if( !f.exists() ){
     f.mkdir();
     }
     
       OutputStream out = new FileOutputStream(new File( directory + "/" + folderName + "/" + imgCount + "."+extName ));  imgCount++;
     out.write( pic.getContent() );
     //pic.writeImageContent(out); //这个方法生成的图片是不可用的, 连图片浏览器都读不了
     out.flush();
     out.close();
     }
     }
     }
    /**
       * @return picture's content as byte array
       */
      public byte[] getContent()
      {
        if (content == null || content.length<=0)
        {
          fillImageContent();
        }
        return content;
      }private void fillImageContent()
      {
        byte[] rawContent = getRawContent();    // HACK: Detect compressed images.  In reality there should be some way to determine
        //       this from the first 32 bytes, but I can't see any similarity between all the
        //       samples I have obtained, nor any similarity in the data block contents.
        if (matchSignature(rawContent, COMPRESSED1, 32) || matchSignature(rawContent, COMPRESSED2, 32))
        {
          try
          {
            InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(rawContent, 33, rawContent.length - 33));
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            /*content = new byte[40960];
            in.read(content);*/
            byte[] buf = new byte[4096];
            int readBytes;
            while ((readBytes = in.read(buf)) > 0)
            {
              out.write(buf, 0, readBytes);
            }
            content = out.toByteArray();
          }
          catch (IOException e)
          {
            // Problems reading from the actual ByteArrayInputStream should never happen
            // so this will only ever be a ZipException.
            log.log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e);
          }
        } else {
          // Raw data is not compressed.
          content = rawContent;
        }
      }public byte[] getRawContent()
      {
        if (rawContent == null || rawContent.length <= 0)
        {
          fillRawImageContent();
        }
        return rawContent;
      }
    private void fillRawImageContent()
      {
        this.rawContent = new byte[size];
        System.arraycopy(_dataStream, pictureBytesStartOffset, rawContent, 0, size);
      }
      

  2.   


    /**
      * 将图片导入到特定的文件夹下面
      * 
      * @param directory : WEB应用当前的路径+存放图片的路径
      * @throws IOException
      */
     public  void extractImagesIntoDirectory( String directory ) throws IOException {  PicturesTable pTable = msWord.getPicturesTable();
     int numCharacterRuns = msWord.getRange().numCharacterRuns();  for (int i = 0; i < numCharacterRuns; i++) {
     CharacterRun characterRun = msWord.getRange().getCharacterRun(i);
     if (pTable.hasPicture(characterRun)) {
     Picture pic = pTable.extractPicture(characterRun, true);
     String extName = pic.suggestFileExtension();
     File f = new File( directory + "/" + folderName );
     if( !f.exists() ){
     f.mkdir();
     }
     
       OutputStream out = new FileOutputStream(new File( directory + "/" + folderName + "/" + imgCount + "."+extName ));  imgCount++;
     out.write( pic.getContent() );
     //pic.writeImageContent(out); //这个方法生成的图片是不可用的, 连图片浏览器都读不了
     out.flush();
     out.close();
     }
     }
     }
    /**
       * @return picture's content as byte array
       */
      public byte[] getContent()
      {
        if (content == null || content.length<=0)
        {
          fillImageContent();
        }
        return content;
      }private void fillImageContent()
      {
        byte[] rawContent = getRawContent();    // HACK: Detect compressed images.  In reality there should be some way to determine
        //       this from the first 32 bytes, but I can't see any similarity between all the
        //       samples I have obtained, nor any similarity in the data block contents.
        if (matchSignature(rawContent, COMPRESSED1, 32) || matchSignature(rawContent, COMPRESSED2, 32))
        {
          try
          {
            InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(rawContent, 33, rawContent.length - 33));
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            /*content = new byte[40960];
            in.read(content);*/
            byte[] buf = new byte[4096];
            int readBytes;
            while ((readBytes = in.read(buf)) > 0)
            {
              out.write(buf, 0, readBytes);
            }
            content = out.toByteArray();
          }
          catch (IOException e)
          {
            // Problems reading from the actual ByteArrayInputStream should never happen
            // so this will only ever be a ZipException.
            log.log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e);
          }
        } else {
          // Raw data is not compressed.
          content = rawContent;
        }
      }public byte[] getRawContent()
      {
        if (rawContent == null || rawContent.length <= 0)
        {
          fillRawImageContent();
        }
        return rawContent;
      }
    private void fillRawImageContent()
      {
        this.rawContent = new byte[size];
        System.arraycopy(_dataStream, pictureBytesStartOffset, rawContent, 0, size);
      }
      

  3.   

    I haven't been using the above...