首页 > 解决方案 > Groovy:由于缺少依赖项 CTPosH,无法加载类 CTAnchor

问题描述

我正在使用 Idea,这是我的 bulid.gradle

dependencies {
compile project(":signer-core")
compile 'org.codehaus.groovy:groovy-all:2.4.8'
def poi_version = "3.17"
compile "org.apache.poi:poi:${poi_version}"
compile "org.apache.poi:poi-ooxml:${poi_version}"
compile "org.apache.poi:poi-ooxml-schemas:${poi_version}"
compile "org.apache.santuario:xmlsec:2.1.0"
testCompile "junit:junit:4.12"
}

当我在我创建的 *.groovy 中编译此代码时:

    private  CTAnchor getAnchorWithGraphic(CTDrawing drawing /*inline drawing*/,
                                       String drawingDescr, boolean behind) throws Exception {

    CTGraphicalObject graphicalobject = drawing.getInlineArray(0).graphic
    long width = drawing.getInlineArray(0).getExtent().getCx()
    long height = drawing.getInlineArray(0).getExtent().getCy()

    String anchorXML =
            "<wp:anchor xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" "
    +"simplePos=\"0\" relativeHeight=\"0\" behindDoc=\""+((behind)?1:0)+"\" locked=\"0\" layoutInCell=\"1\""
    +"allowOverlap=\"1\">"
    +"<wp:simplePos x=\"0\" y=\"0\"/>"
    +"<wp:positionH relativeFrom=\"column\"><wp:posOffset>0</wp:posOffset></wp:positionH>"
    +"<wp:positionV relativeFrom=\"paragraph\"><wp:posOffset>0</wp:posOffset></wp:positionV>"
    +"<wp:extent cx=\""+width+"\" cy=\""+height+"\"/>"
    +"<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/><wp:wrapNone/>"
    +"<wp:docPr id=\"1\" name=\"Drawing 0\" descr=\""+drawingDescr+"\"/><wp:cNvGraphicFramePr/>"
    +"</wp:anchor>"

    drawing = CTDrawing.Factory.parse(anchorXML)
    CTAnchor anchor = drawing.getAnchorArray(0)

    anchor.setGraphic(graphicalobject)
    return anchor
}

它有一些错误:

错误:Groovyc:编译signer-office_main时:java.lang.RuntimeException:java.lang.NoClassDefFoundError:由于缺少依赖项org/openxmlformats/schemas/drawingml,无法加载类org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor /x2006/wordprocessing绘图/CTPosH

但是代码可以在我创建的 *.java 中运行。我进入CTAnchor.class检查CTPosH,它真的找不到声明去。但这是最新的apache poi版本。

在此处输入图像描述

标签: javagroovyapache-poi

解决方案


推荐阅读