Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalStateException when trying to setFillColor using Apache POI XSLF

I'm trying to set the background fill color for a pptx file using the Apache POI XSLF library. My code looks like this:

XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
XSLFSlideLayout layout = defaultMaster.getLayout(SlideLayout.BLANK);
XSLFBackground background = layout.getBackground();
background.setFillColor(Color.BLACK);

which results in

Exception in thread "main" java.lang.IllegalStateException: CTShapeProperties was not found.
at org.apache.poi.xslf.usermodel.XSLFShape.getSpPr(XSLFShape.java:240)
at org.apache.poi.xslf.usermodel.XSLFSimpleShape.setFillColor(XSLFSimpleShape.java:549)

I've tried calling this on SlideMaster's background, the layout's background, and the slide's background and all result in the same error.

like image 745
Kaptain Avatar asked Aug 23 '16 17:08

Kaptain


1 Answers

This was fixed in POI 3.15-beta2 via #59702.

The "problem" with the OOXml properties or the POI implementation or the xmlbeans schemas is, that similar attributes like colors are stored below different schema types and the old code didn't cover that parent nodes. The patch introduced delegates to wrap those differences and the XSLF usermodel methods can be now more uniform.

like image 90
kiwiwings Avatar answered Oct 28 '22 07:10

kiwiwings