java-使用Apache POI获取.xlsx文件中图像的图像位置/位置
作者:互联网
我只能通过此方法获取图像数据.getAllPictures()
List<XSSFPictureData> lst = (List)workbook.getAllPictures();
每当我使用getShapes()时我都会得到这个
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
at org.codehaus.groovy.tools.javac.JavacJavaCompiler.addJavacError(JavacJavaCompiler.java:92)
at org.codehaus.groovy.tools.javac.JavacJavaCompiler.compile(JavacJavaCompiler.java:71)
at org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit.gotoPhase(JavaAwareCompilationUnit.java:97)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:529)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:498)
at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:55)
at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:210)
at org.codehaus.groovy.ant.Groovyc.runCompiler(Groovyc.java:1078)
at org.codehaus.groovy.ant.Groovyc.compile(Groovyc.java:1129)
at org.codehaus.groovy.ant.Groovyc.execute(Groovyc.java:748)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
2015-04-21 09:54:36,457错误StackTrace完整堆栈跟踪:
org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败:
有可能还是有办法让我在.xlsx文件中获取图像位置/位置?
解决方法:
您可以通过XSSFPicture.getClientAnchor()方法检索位置,ClientAnchor具有行/列位置和像素偏移量,该偏移量应允许获取您要查找的信息,例如:
XSSFDrawing dp = wb.getSheetAt(0).createDrawingPatriarch();
List<XSSFShape> pics = dp.getShapes();
XSSFPicture inpPic = (XSSFPicture)pics.get(0);
XSSFClientAnchor clientAnchor = inpPic.getClientAnchor();
System.out.println("col1: " + clientAnchor.getCol1() + ", col2: " + clientAnchor.getCol2() + ", row1: " + clientAnchor.getRow1() + ", row2: " + clientAnchor.getRow2());
System.out.println("x1: " + clientAnchor.getDx1() + ", x2: " + clientAnchor.getDx2() + ", y1: " + clientAnchor.getDy1() + ", y2: " + clientAnchor.getDy2());
将打印出类似
col1: 0, col2: 2, row1: 1, row2: 7
x1: 252000, x2: 63720, y1: 60480, y2: 201600
标签:apache-poi,java,excel 来源: https://codeday.me/bug/20191120/2044275.html