IllegalStateException when trying to setFillColor using Apache POI XSLF

395 Views Asked by At

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.

1

There are 1 best solutions below

3
On

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.