解决方案 »

  1.   

    插入图片使用的方法是XWPFRun的AddPicture方法
      

  2.   

    npoi用过,貌似是和office版本有关,有兼容性问题,楼主这方面找找原因
    我只搞过excel的。
      

  3.   


    对的,我以前也只搞过excel
    NPOI支持excel2003/2007
    对word只支持2007且并不稳定
      

  4.   


    对的,我以前也只搞过excel
    NPOI支持excel2003/2007
    对word只支持2007且并不稳定
    用最低兼容版本
      

  5.   


    对的,我以前也只搞过excel
    NPOI支持excel2003/2007
    对word只支持2007且并不稳定
    用最低兼容版本
    比如?
      

  6.   

    亲,NPOI插入图片你实现了吗,我现在也遇到这样问题了。
      

  7.   

    Aspose.Words
    生成word方法http://www.cnblogs.com/rhythmK/archive/2011/12/05/2276651.htmldll这个链接也有附件6.05版本的,可以生成word2003
      

  8.   

    我稍微重写了addPicture方法,
    可以在指定的地方插入图片了 我刚测试过
    希望对你有用:public void addPictureNew(InputStream pictureData, int pictureType, String filename, int width, int height)
        throws InvalidFormatException, IOException {
            XWPFDocument doc = paragraph.document;
            String relationId = doc.addPictureData(pictureData, pictureType);
            final int EMU = 9525;    
            width *= EMU;    
            height *= EMU;    
            String blipId = "1";    
        
            CTInline inline = paragraph.createRun().getCTR()    
                    .addNewDrawing().addNewInline();    
            paragraph.createRun().setText("");  
            String picXml = ""    
                    + "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"    
                    + "   <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"    
                    + "      <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"    
                    + "         <pic:nvPicPr>" + "            <pic:cNvPr id=\""    
                    + 0    
                    + "\" name=\"Generated\"/>"    
                    + "            <pic:cNvPicPr/>"    
                    + "         </pic:nvPicPr>"    
                    + "         <pic:blipFill>"    
                    + "            <a:blip r:embed=\""    
                    + relationId    
                    + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>"    
                    + "            <a:stretch>"    
                    + "               <a:fillRect/>"    
                    + "            </a:stretch>"    
                    + "         </pic:blipFill>"    
                    + "         <pic:spPr>"    
                    + "            <a:xfrm>"    
                    + "               <a:off x=\"0\" y=\"0\"/>"    
                    + "               <a:ext cx=\""    
                    + width    
                    + "\" cy=\""    
                    + height    
                    + "\"/>"    
                    + "            </a:xfrm>"    
                    + "            <a:prstGeom prst=\"rect\">"    
                    + "               <a:avLst/>"    
                    + "            </a:prstGeom>"    
                    + "         </pic:spPr>"    
                    + "      </pic:pic>"    
                    + "   </a:graphicData>" + "</a:graphic>";    
        
            // CTGraphicalObjectData graphicData =     
            inline.addNewGraphic().addNewGraphicData();    
            XmlToken xmlToken = null;    
            try {    
                xmlToken = XmlToken.Factory.parse(picXml);    
            } catch (XmlException xe) {    
                xe.printStackTrace();    
            }    
            inline.set(xmlToken);    
            // graphicData.set(xmlToken);     
        
            inline.setDistT(0);    
            inline.setDistB(0);    
            inline.setDistL(0);    
            inline.setDistR(0);    
        
            CTPositiveSize2D extent = inline.addNewExtent();    
            extent.setCx(width);    
            extent.setCy(height);    
        
            CTNonVisualDrawingProps docPr = inline.addNewDocPr();    
            docPr.setId(pictureType);    
            docPr.setName("图片" + pictureType);    
            docPr.setDescr("");   
            
        }
      

  9.   

    参看http://blog.csdn.net/gltide/article/details/21191357