Reputation: 31
I can only get the image data through this method .getAllPictures()
List<XSSFPictureData> lst = (List)workbook.getAllPictures();
I get this whenever I use the 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 ERROR StackTrace Full Stack Trace: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Is it possible or is there a way so I can get the image position/location in a .xlsx file?
Upvotes: 3
Views: 3138
Reputation: 15872
You can retrieve the position via the XSSFPicture.getClientAnchor() method, the ClientAnchor has a row/column location and an pixel-offset which should allow to get the information you are looking for, e.g.:
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());
will print out something like
col1: 0, col2: 2, row1: 1, row2: 7
x1: 252000, x2: 63720, y1: 60480, y2: 201600
Upvotes: 3