Java 添加了docx4j但未显示在文档中的椭圆

Java 添加了docx4j但未显示在文档中的椭圆,java,docx4j,Java,Docx4j,我通过docx4j将椭圆添加到docx文档中,如下所示: String xmlEllipse = getXmlEllipse(); Object ellipse = XmlUtils.unmarshalString(xmlEllipse); Graphic ellipseGraphic = (Graphic) ((JAXBElement)ellipse).getValue(); Anchor anchor = new Anchor(); anchor.setGraphic(ellipseGra

我通过docx4j将椭圆添加到docx文档中,如下所示:

String xmlEllipse = getXmlEllipse();
Object ellipse = XmlUtils.unmarshalString(xmlEllipse);
Graphic ellipseGraphic = (Graphic) ((JAXBElement)ellipse).getValue();

Anchor anchor = new Anchor();
anchor.setGraphic(ellipseGraphic);

ObjectFactory factory = new ObjectFactory();
P paragraph = factory.createP();
R run = factory.createR();
paragraph.getContent().add(run);
Drawing drawing = factory.createDrawing();
run.getContent().add(drawing);
drawing.getAnchorOrInline().add(anchor);

WordprocessingMLPackage newDoc = WordprocessingMLPackage.createPackage();
newDoc.getMainDocumentPart().getContent().add(paragraph);

newDoc.save(new File(dirPath + outputFilePath));
CTPoint2D simplePos = new CTPoint2D();
simplePos.setX(0L);
simplePos.setY(0L);
anchor.setSimplePos(simplePos);

CTPosH ctPosH = new CTPosH();
ctPosH.setRelativeFrom(STRelFromH.COLUMN);
ctPosH.setPosOffset(904875);
anchor.setPositionH(ctPosH);

CTPosV ctPosV = new CTPosV();
ctPosV.setRelativeFrom(STRelFromV.PARAGRAPH);
ctPosV.setPosOffset(514350);
anchor.setPositionV(ctPosV);

CTPositiveSize2D ctPositiveSize2D = new CTPositiveSize2D();
ctPositiveSize2D.setCx(2238375);
ctPositiveSize2D.setCy(1057275);
anchor.setExtent(ctPositiveSize2D);


CTEffectExtent ctEffectExtent = new CTEffectExtent();
ctEffectExtent.setL(0);
ctEffectExtent.setT(0);
ctEffectExtent.setR(28575);
ctEffectExtent.setB(28575);
anchor.setEffectExtent(ctEffectExtent);

CTWrapNone ctWrapNone = new CTWrapNone();
anchor.setWrapNone(ctWrapNone);

CTNonVisualDrawingProps ctNonVisualDrawingProps = new CTNonVisualDrawingProps();
ctNonVisualDrawingProps.setId(1);
ctNonVisualDrawingProps.setName("Oval 1");
anchor.setDocPr(ctNonVisualDrawingProps);

CTNonVisualGraphicFrameProperties ctNonVisualGraphicFrameProperties = new CTNonVisualGraphicFrameProperties();
anchor.setCNvGraphicFramePr(ctNonVisualGraphicFrameProperties);
getXmlEllipse方法如下所示:

private static String getXmlEllipse() {
        String xmlEllipse = ""
                + " <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
                + "     <a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
                + "         <wps:wsp>"
                + "             <wps:cNvSpPr/>"
                + "             <wps:spPr>"
                + "                 <a:xfrm>"
                + "                     <a:off x=\"0\" y=\"0\"/>"
                + "                     <a:ext cx=\"130629\" cy=\"130629\"/>"
                + "                     </a:xfrm>"
                + "                 <a:prstGeom prst=\"ellipse\">"
                + "                     <a:avLst/>"
                + "                 </a:prstGeom>"
                + "             </wps:spPr>"
                + "             <wps:style>"
                + "                 <a:lnRef idx=\"2\">"
                + "                     <a:schemeClr val=\"accent1\">"
                + "                         <a:shade val=\"50000\"/>"
                + "                     </a:schemeClr>"
                + "                 </a:lnRef>"
                + "                 <a:fillRef idx=\"1\">"
                + "                     <a:schemeClr val=\"accent1\"/>"
                + "                 </a:fillRef>"
                + "                 <a:effectRef idx=\"0\">"
                + "                     <a:schemeClr val=\"accent1\"/>"
                + "                 </a:effectRef>"
                + "                 <a:fontRef idx=\"minor\">"
                + "                     <a:schemeClr val=\"lt1\"/>"
                + "                 </a:fontRef>"
                + "             </wps:style>"
                + "             <wps:bodyPr rot=\"0\" spcFirstLastPara=\"0\" vertOverflow=\"overflow\" horzOverflow=\"overflow\" vert=\"horz\" wrap=\"square\" lIns=\"91440\" tIns=\"45720\" rIns=\"91440\" bIns=\"45720\" numCol=\"1\" spcCol=\"0\" rtlCol=\"0\" fromWordArt=\"0\" anchor=\"ctr\" anchorCtr=\"0\" forceAA=\"0\" compatLnSpc=\"1\">"
                + "                 <a:prstTxWarp prst=\"textNoShape\">"
                + "                     <a:avLst/>"
                + "                 </a:prstTxWarp>"
                + "                 <a:noAutofit/>"
                + "             </wps:bodyPr>"
                + "         </wps:wsp>"
                + "     </a:graphicData>"
                + " </a:graphic>";

        return xmlEllipse;
    }
private static String getXmlAnchor() {
    String xmlAnchor = ""
            + "<wp:anchor xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" distT=\"0\" distB=\"0\" distL=\"114300\" distR=\"114300\" simplePos=\"0\" relativeHeight=\"251659264\" behindDoc=\"0\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"
            + "     <wp:simplePos x=\"0\" y=\"0\"/>"
            + "     <wp:positionH relativeFrom=\"column\">"
            + "         <wp:posOffset>606161</wp:posOffset>"
            + "     </wp:positionH>"
            + "     <wp:positionV relativeFrom=\"paragraph\">"
            + "         <wp:posOffset>287737</wp:posOffset>"
            + "     </wp:positionV>"
            + "     <wp:extent cx=\"130629\" cy=\"130629\"/>"
            + "     <wp:effectExtent l=\"0\" t=\"0\" r=\"22225\" b=\"22225\"/>"
            + "     <wp:wrapNone/>"
            + "     <wp:docPr id=\"1\" name=\"1 Elipse\"/>"
            + "     <wp:cNvGraphicFramePr/>"
            + "     <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"
            + "         <a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
            + "             <wps:wsp>"
            + "                 <wps:cNvSpPr/>"
            + "                 <wps:spPr>"
            + "                     <a:xfrm>"
            + "                         <a:off x=\"0\" y=\"0\"/>"
            + "                         <a:ext cx=\"130629\" cy=\"130629\"/>"
            + "                     </a:xfrm>"
            + "                     <a:prstGeom prst=\"ellipse\">"
            + "                         <a:avLst/>"
            + "                     </a:prstGeom>"
            + "                 </wps:spPr>"
            + "                 <wps:style>"
            + "                     <a:lnRef idx=\"2\">"
            + "                         <a:schemeClr val=\"accent1\">"
            + "                             <a:shade val=\"50000\"/>"
            + "                         </a:schemeClr>"
            + "                     </a:lnRef>"
            + "                     <a:fillRef idx=\"1\">"
            + "                         <a:schemeClr val=\"accent1\"/>"
            + "                     </a:fillRef>"
            + "                     <a:effectRef idx=\"0\">"
            + "                         <a:schemeClr val=\"accent1\"/>"
            + "                     </a:effectRef>"
            + "                     <a:fontRef idx=\"minor\">"
            + "                         <a:schemeClr val=\"lt1\"/>"
            + "                     </a:fontRef>"
            + "                 </wps:style>"
            + "                 <wps:bodyPr rot=\"0\" spcFirstLastPara=\"0\" vertOverflow=\"overflow\" horzOverflow=\"overflow\" vert=\"horz\" wrap=\"square\" lIns=\"91440\" tIns=\"45720\" rIns=\"91440\" bIns=\"45720\" numCol=\"1\" spcCol=\"0\" rtlCol=\"0\" fromWordArt=\"0\" anchor=\"ctr\" anchorCtr=\"0\" forceAA=\"0\" compatLnSpc=\"1\">"
            + "                     <a:prstTxWarp prst=\"textNoShape\">"
            + "                         <a:avLst/>"
            + "                     </a:prstTxWarp>"
            + "                     <a:noAutofit/>"
            + "                 </wps:bodyPr>"
            + "             </wps:wsp>"
            + "         </a:graphicData>"
            + "     </a:graphic>"
            + "     <wp14:sizeRelH relativeFrom=\"margin\">"
            + "         <wp14:pctWidth>0</wp14:pctWidth>"
            + "     </wp14:sizeRelH>"
            + "     <wp14:sizeRelV relativeFrom=\"margin\">"
            + "         <wp14:pctHeight>0</wp14:pctHeight>"
            + "     </wp14:sizeRelV>"
            + "</wp:anchor>";

    return xmlAnchor;
}
distT="0" distB="0" distL="114300" distR="114300" simplePos="0"
对于w:drawing,缺少属性的类org.docx4j.wml.drawing似乎没有适当的方法,如setDistT等。类org.docx4j.dml.wordprocessingDrawing.Anchor有这些方法,因此我尝试了:

anchor.setSimplePosAttr(false);
anchor.setRelativeHeight(251659264);
anchor.setDistB(0L);
anchor.setDistT(0L);
anchor.setDistL(114300L);
anchor.setDistR(114300L);
anchor.setAllowOverlap(true);
anchor.setLayoutInCell(true);
结果是无法在MS Word中打开文档,并在Libre Office中显示为空白文档。这是docx文档中生成的document.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:ns8="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:ns12="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram" xmlns:ns17="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:ns21="urn:schemas-microsoft-com:office:powerpoint" xmlns:ns23="http://schemas.microsoft.com/office/2006/coverPageProps" xmlns:odx="http://opendope.org/xpaths" xmlns:odc="http://opendope.org/conditions" xmlns:odq="http://opendope.org/questions" xmlns:oda="http://opendope.org/answers" xmlns:odi="http://opendope.org/components" xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy" xmlns:ns30="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns:ns31="http://schemas.openxmlformats.org/drawingml/2006/compatibility" xmlns:ns32="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" mc:Ignorable="w14 w15">
    <w:body>
        <w:p w14:paraId="18541d2" w14:textId="18541d2">
            <w:pPr>
                <w15:collapsed w:val="false"/>
            </w:pPr>
            <w:r>
                <w:drawing>
                    <wp:anchor distT="0" distB="0" distL="114300" distR="114300" relativeHeight="251659264" behindDoc="false" locked="false" layoutInCell="true" allowOverlap="true">
                        <wp:simplePos x="0" y="0"/>
                        <wp:positionH relativeFrom="column">
                            <wp:posOffset>904875</wp:posOffset>
                        </wp:positionH>
                        <wp:positionV relativeFrom="paragraph">
                            <wp:posOffset>514350</wp:posOffset>
                        </wp:positionV>
                        <wp:extent cx="2238375" cy="1057275"/>
                        <wp:effectExtent l="0" t="0" r="28575" b="28575"/>
                        <wp:wrapNone/>
                        <wp:docPr id="1" name="Oval 1"/>
                        <wp:cNvGraphicFramePr/>
                        <a:graphic>
                            <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                                <wps:wsp xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
                                    <wps:cNvSpPr/>
                                    <wps:spPr>
                                        <a:xfrm>
                                            <a:off x="0" y="0"/>
                                            <a:ext cx="130629" cy="130629"/>
                                        </a:xfrm>
                                        <a:prstGeom prst="ellipse">
                                            <a:avLst/>
                                        </a:prstGeom>
                                    </wps:spPr>
                                    <wps:style>
                                        <a:lnRef idx="2">
                                            <a:schemeClr val="accent1">
                                                <a:shade val="50000"/>
                                            </a:schemeClr>
                                        </a:lnRef>
                                        <a:fillRef idx="1">
                                            <a:schemeClr val="accent1"/>
                                        </a:fillRef>
                                        <a:effectRef idx="0">
                                            <a:schemeClr val="accent1"/>
                                        </a:effectRef>
                                        <a:fontRef idx="minor">
                                            <a:schemeClr val="lt1"/>
                                        </a:fontRef>
                                    </wps:style>
                                    <wps:bodyPr anchor="ctr" anchorCtr="0" bIns="45720" compatLnSpc="1" forceAA="0" fromWordArt="0" horzOverflow="overflow" lIns="91440" numCol="1" rIns="91440" rot="0" rtlCol="0" spcCol="0" spcFirstLastPara="0" tIns="45720" vert="horz" vertOverflow="overflow" wrap="square">
                                        <a:prstTxWarp prst="textNoShape">
                                            <a:avLst/>
                                        </a:prstTxWarp>
                                        <a:noAutofit/>
                                    </wps:bodyPr>
                                </wps:wsp>
                            </a:graphicData>
                        </a:graphic>
                    </wp:anchor>
                </w:drawing>
            </w:r>
        </w:p>
        <w:sectPr>
            <w:pgSz w:w="11907" w:h="16839" w:code="9"/>
            <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"/>
        </w:sectPr>
    </w:body>
</w:document>
getXmlAnchor方法如下所示:

private static String getXmlEllipse() {
        String xmlEllipse = ""
                + " <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
                + "     <a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
                + "         <wps:wsp>"
                + "             <wps:cNvSpPr/>"
                + "             <wps:spPr>"
                + "                 <a:xfrm>"
                + "                     <a:off x=\"0\" y=\"0\"/>"
                + "                     <a:ext cx=\"130629\" cy=\"130629\"/>"
                + "                     </a:xfrm>"
                + "                 <a:prstGeom prst=\"ellipse\">"
                + "                     <a:avLst/>"
                + "                 </a:prstGeom>"
                + "             </wps:spPr>"
                + "             <wps:style>"
                + "                 <a:lnRef idx=\"2\">"
                + "                     <a:schemeClr val=\"accent1\">"
                + "                         <a:shade val=\"50000\"/>"
                + "                     </a:schemeClr>"
                + "                 </a:lnRef>"
                + "                 <a:fillRef idx=\"1\">"
                + "                     <a:schemeClr val=\"accent1\"/>"
                + "                 </a:fillRef>"
                + "                 <a:effectRef idx=\"0\">"
                + "                     <a:schemeClr val=\"accent1\"/>"
                + "                 </a:effectRef>"
                + "                 <a:fontRef idx=\"minor\">"
                + "                     <a:schemeClr val=\"lt1\"/>"
                + "                 </a:fontRef>"
                + "             </wps:style>"
                + "             <wps:bodyPr rot=\"0\" spcFirstLastPara=\"0\" vertOverflow=\"overflow\" horzOverflow=\"overflow\" vert=\"horz\" wrap=\"square\" lIns=\"91440\" tIns=\"45720\" rIns=\"91440\" bIns=\"45720\" numCol=\"1\" spcCol=\"0\" rtlCol=\"0\" fromWordArt=\"0\" anchor=\"ctr\" anchorCtr=\"0\" forceAA=\"0\" compatLnSpc=\"1\">"
                + "                 <a:prstTxWarp prst=\"textNoShape\">"
                + "                     <a:avLst/>"
                + "                 </a:prstTxWarp>"
                + "                 <a:noAutofit/>"
                + "             </wps:bodyPr>"
                + "         </wps:wsp>"
                + "     </a:graphicData>"
                + " </a:graphic>";

        return xmlEllipse;
    }
private static String getXmlAnchor() {
    String xmlAnchor = ""
            + "<wp:anchor xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" distT=\"0\" distB=\"0\" distL=\"114300\" distR=\"114300\" simplePos=\"0\" relativeHeight=\"251659264\" behindDoc=\"0\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"
            + "     <wp:simplePos x=\"0\" y=\"0\"/>"
            + "     <wp:positionH relativeFrom=\"column\">"
            + "         <wp:posOffset>606161</wp:posOffset>"
            + "     </wp:positionH>"
            + "     <wp:positionV relativeFrom=\"paragraph\">"
            + "         <wp:posOffset>287737</wp:posOffset>"
            + "     </wp:positionV>"
            + "     <wp:extent cx=\"130629\" cy=\"130629\"/>"
            + "     <wp:effectExtent l=\"0\" t=\"0\" r=\"22225\" b=\"22225\"/>"
            + "     <wp:wrapNone/>"
            + "     <wp:docPr id=\"1\" name=\"1 Elipse\"/>"
            + "     <wp:cNvGraphicFramePr/>"
            + "     <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"
            + "         <a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
            + "             <wps:wsp>"
            + "                 <wps:cNvSpPr/>"
            + "                 <wps:spPr>"
            + "                     <a:xfrm>"
            + "                         <a:off x=\"0\" y=\"0\"/>"
            + "                         <a:ext cx=\"130629\" cy=\"130629\"/>"
            + "                     </a:xfrm>"
            + "                     <a:prstGeom prst=\"ellipse\">"
            + "                         <a:avLst/>"
            + "                     </a:prstGeom>"
            + "                 </wps:spPr>"
            + "                 <wps:style>"
            + "                     <a:lnRef idx=\"2\">"
            + "                         <a:schemeClr val=\"accent1\">"
            + "                             <a:shade val=\"50000\"/>"
            + "                         </a:schemeClr>"
            + "                     </a:lnRef>"
            + "                     <a:fillRef idx=\"1\">"
            + "                         <a:schemeClr val=\"accent1\"/>"
            + "                     </a:fillRef>"
            + "                     <a:effectRef idx=\"0\">"
            + "                         <a:schemeClr val=\"accent1\"/>"
            + "                     </a:effectRef>"
            + "                     <a:fontRef idx=\"minor\">"
            + "                         <a:schemeClr val=\"lt1\"/>"
            + "                     </a:fontRef>"
            + "                 </wps:style>"
            + "                 <wps:bodyPr rot=\"0\" spcFirstLastPara=\"0\" vertOverflow=\"overflow\" horzOverflow=\"overflow\" vert=\"horz\" wrap=\"square\" lIns=\"91440\" tIns=\"45720\" rIns=\"91440\" bIns=\"45720\" numCol=\"1\" spcCol=\"0\" rtlCol=\"0\" fromWordArt=\"0\" anchor=\"ctr\" anchorCtr=\"0\" forceAA=\"0\" compatLnSpc=\"1\">"
            + "                     <a:prstTxWarp prst=\"textNoShape\">"
            + "                         <a:avLst/>"
            + "                     </a:prstTxWarp>"
            + "                     <a:noAutofit/>"
            + "                 </wps:bodyPr>"
            + "             </wps:wsp>"
            + "         </a:graphicData>"
            + "     </a:graphic>"
            + "     <wp14:sizeRelH relativeFrom=\"margin\">"
            + "         <wp14:pctWidth>0</wp14:pctWidth>"
            + "     </wp14:sizeRelH>"
            + "     <wp14:sizeRelV relativeFrom=\"margin\">"
            + "         <wp14:pctHeight>0</wp14:pctHeight>"
            + "     </wp14:sizeRelV>"
            + "</wp:anchor>";

    return xmlAnchor;
}
distT="0" distB="0" distL="114300" distR="114300" simplePos="0"

您的问题是,对于Word 2010,您在w:drawing上缺少一些必需的属性

您需要以下部分或全部内容:

private static String getXmlEllipse() {
        String xmlEllipse = ""
                + " <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
                + "     <a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
                + "         <wps:wsp>"
                + "             <wps:cNvSpPr/>"
                + "             <wps:spPr>"
                + "                 <a:xfrm>"
                + "                     <a:off x=\"0\" y=\"0\"/>"
                + "                     <a:ext cx=\"130629\" cy=\"130629\"/>"
                + "                     </a:xfrm>"
                + "                 <a:prstGeom prst=\"ellipse\">"
                + "                     <a:avLst/>"
                + "                 </a:prstGeom>"
                + "             </wps:spPr>"
                + "             <wps:style>"
                + "                 <a:lnRef idx=\"2\">"
                + "                     <a:schemeClr val=\"accent1\">"
                + "                         <a:shade val=\"50000\"/>"
                + "                     </a:schemeClr>"
                + "                 </a:lnRef>"
                + "                 <a:fillRef idx=\"1\">"
                + "                     <a:schemeClr val=\"accent1\"/>"
                + "                 </a:fillRef>"
                + "                 <a:effectRef idx=\"0\">"
                + "                     <a:schemeClr val=\"accent1\"/>"
                + "                 </a:effectRef>"
                + "                 <a:fontRef idx=\"minor\">"
                + "                     <a:schemeClr val=\"lt1\"/>"
                + "                 </a:fontRef>"
                + "             </wps:style>"
                + "             <wps:bodyPr rot=\"0\" spcFirstLastPara=\"0\" vertOverflow=\"overflow\" horzOverflow=\"overflow\" vert=\"horz\" wrap=\"square\" lIns=\"91440\" tIns=\"45720\" rIns=\"91440\" bIns=\"45720\" numCol=\"1\" spcCol=\"0\" rtlCol=\"0\" fromWordArt=\"0\" anchor=\"ctr\" anchorCtr=\"0\" forceAA=\"0\" compatLnSpc=\"1\">"
                + "                 <a:prstTxWarp prst=\"textNoShape\">"
                + "                     <a:avLst/>"
                + "                 </a:prstTxWarp>"
                + "                 <a:noAutofit/>"
                + "             </wps:bodyPr>"
                + "         </wps:wsp>"
                + "     </a:graphicData>"
                + " </a:graphic>";

        return xmlEllipse;
    }
private static String getXmlAnchor() {
    String xmlAnchor = ""
            + "<wp:anchor xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" distT=\"0\" distB=\"0\" distL=\"114300\" distR=\"114300\" simplePos=\"0\" relativeHeight=\"251659264\" behindDoc=\"0\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\">"
            + "     <wp:simplePos x=\"0\" y=\"0\"/>"
            + "     <wp:positionH relativeFrom=\"column\">"
            + "         <wp:posOffset>606161</wp:posOffset>"
            + "     </wp:positionH>"
            + "     <wp:positionV relativeFrom=\"paragraph\">"
            + "         <wp:posOffset>287737</wp:posOffset>"
            + "     </wp:positionV>"
            + "     <wp:extent cx=\"130629\" cy=\"130629\"/>"
            + "     <wp:effectExtent l=\"0\" t=\"0\" r=\"22225\" b=\"22225\"/>"
            + "     <wp:wrapNone/>"
            + "     <wp:docPr id=\"1\" name=\"1 Elipse\"/>"
            + "     <wp:cNvGraphicFramePr/>"
            + "     <a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"
            + "         <a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">"
            + "             <wps:wsp>"
            + "                 <wps:cNvSpPr/>"
            + "                 <wps:spPr>"
            + "                     <a:xfrm>"
            + "                         <a:off x=\"0\" y=\"0\"/>"
            + "                         <a:ext cx=\"130629\" cy=\"130629\"/>"
            + "                     </a:xfrm>"
            + "                     <a:prstGeom prst=\"ellipse\">"
            + "                         <a:avLst/>"
            + "                     </a:prstGeom>"
            + "                 </wps:spPr>"
            + "                 <wps:style>"
            + "                     <a:lnRef idx=\"2\">"
            + "                         <a:schemeClr val=\"accent1\">"
            + "                             <a:shade val=\"50000\"/>"
            + "                         </a:schemeClr>"
            + "                     </a:lnRef>"
            + "                     <a:fillRef idx=\"1\">"
            + "                         <a:schemeClr val=\"accent1\"/>"
            + "                     </a:fillRef>"
            + "                     <a:effectRef idx=\"0\">"
            + "                         <a:schemeClr val=\"accent1\"/>"
            + "                     </a:effectRef>"
            + "                     <a:fontRef idx=\"minor\">"
            + "                         <a:schemeClr val=\"lt1\"/>"
            + "                     </a:fontRef>"
            + "                 </wps:style>"
            + "                 <wps:bodyPr rot=\"0\" spcFirstLastPara=\"0\" vertOverflow=\"overflow\" horzOverflow=\"overflow\" vert=\"horz\" wrap=\"square\" lIns=\"91440\" tIns=\"45720\" rIns=\"91440\" bIns=\"45720\" numCol=\"1\" spcCol=\"0\" rtlCol=\"0\" fromWordArt=\"0\" anchor=\"ctr\" anchorCtr=\"0\" forceAA=\"0\" compatLnSpc=\"1\">"
            + "                     <a:prstTxWarp prst=\"textNoShape\">"
            + "                         <a:avLst/>"
            + "                     </a:prstTxWarp>"
            + "                     <a:noAutofit/>"
            + "                 </wps:bodyPr>"
            + "             </wps:wsp>"
            + "         </a:graphicData>"
            + "     </a:graphic>"
            + "     <wp14:sizeRelH relativeFrom=\"margin\">"
            + "         <wp14:pctWidth>0</wp14:pctWidth>"
            + "     </wp14:sizeRelH>"
            + "     <wp14:sizeRelV relativeFrom=\"margin\">"
            + "         <wp14:pctHeight>0</wp14:pctHeight>"
            + "     </wp14:sizeRelV>"
            + "</wp:anchor>";

    return xmlAnchor;
}
distT="0" distB="0" distL="114300" distR="114300" simplePos="0"
此外,您还需要wp:anchor的以下部分或全部额外子项:

            <wp:simplePos x="0" y="0"/>
        <wp:positionH relativeFrom="column">
          <wp:posOffset>904875</wp:posOffset>
        </wp:positionH>
        <wp:positionV relativeFrom="paragraph">
          <wp:posOffset>514350</wp:posOffset>
        </wp:positionV>
        <wp:extent cx="2238375" cy="1057275"/>
        <wp:effectExtent l="0" t="0" r="28575" b="28575"/>
        <wp:wrapNone/>
        <wp:docPr id="1" name="Oval 1"/>
        <wp:cNvGraphicFramePr/>

我还没有费心去弄清楚Word 2010要快乐需要什么子集;如果你这么做了,请带着你的发现回来

已经试过了,但还没有成功。我用附加信息编辑了我的问题。谢谢。您缺少simplePos=0;当我添加它时,它对我有效。org.docx4j.dml.wordprocessingDrawing.Anchor类有一个方法setSimplePosAttr,它接受一个布尔参数并生成一个xml属性simplePos=false。而且也不起作用。org.docx4j.wml.Drawing类没有类似的方法。为了正确地设置simplePos=0而不是simplePos=false,它们在许多语言中是否等效?我努力从外部锚标记编码xml部分,同时也避免了大量java代码。终于成功了。我编辑我的问题以显示新场景。非常感谢您对JasonPlutext的支持。这很奇怪,因为unmarshalString和setSimplePotatr的结果应该是相同的!也许我错过了什么。我做了很多测试,我不能确定。