public static byte[] insertPicToDocx(InputStream in,List fushionChartList,List chartIndicatorType)throws Exception { LoadFromZipNG z = new LoadFromZipNG(); WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage)z.get(in); MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); wordMLPackage.getParts().get(new PartName("/word/_rels/document.xml.rels")); /**2011-5-25 新图的ID+图的描述**/ final HashMap picMap=new HashMap(); /**2011-5-25 将所有生成的图片绑定到文档**/ for(int i=0;i apply(Object o) { String text = ""; /**是否是在图片部分*/ if (o instanceof org.docx4j.wml.Drawing) { String desc=((Anchor) ((org.docx4j.wml.Drawing) o).getAnchorOrInline().get(0)).getDocPr() .getDescr(); for (int k = 0; k < picMap.keySet().size(); k++) { String key =(String) picMap.keySet().toArray()[k]; String value = "[["+picMap.get(key)+"]]"; if(!value.equals(desc)) { continue; } else { ((Anchor) ((org.docx4j.wml.Drawing) o) .getAnchorOrInline().get(0)).getGraphic() .getGraphicData().getPic().getBlipFill() .getBlip().setEmbed(key); break; } } } return null; } public boolean shouldTraverse(Object o) { return true; } // Depth first public void walkJAXBElements(Object parent) { indent += " "; List children = getChildren(parent); if (children != null) { for (Object o : children) { // if its wrapped in javax.xml.bind.JAXBElement, get its // value o = XmlUtils.unwrap(o); System.out.println("类型:"+o); this.apply(o); if (this.shouldTraverse(o)) { walkJAXBElements(o); } } } indent = indent.substring(0, indent.length() - 4); } public List getChildren(Object o) { return TraversalUtil.getChildrenImpl(o); } } ); ByteArrayOutputStream fos=new ByteArrayOutputStream(); SaveToZipFile saver = new SaveToZipFile(wordMLPackage); saver.save(fos); byte[] reval=fos.toByteArray(); return reval; }