简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM