我正在使用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 /,无法加载类org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor模式/ drawingml / x2006 / wordprocessingDrawing / CTPosH
但代码可以在我创建的* .java中运行。 我进入 CTAnchor.class 检查 CTPOSH ,它实际上找不到声明。但这是最新的 apache poi 版本。