ERROR : Caused by: java.lang.IllegalArgumentException: Relationship null doesn't start with this part /ppt/slides/slide3.xml

笑着哭i 提交于 2019-12-12 01:26:48

问题


I'm working with apache poi xslf to export ppt file. First, I have a template set with 3 slides : title slide, summary slide, and third slide

I duplicate the 3rd slide (i have it as a template) in order to copy many data/graphics as I have in database.

So in order to do that :

XMLSlideShow slideShow = new XMLSlideShow(dlfile.getContentStream());
XSLFSlide[] slides = slideShow.getSlides();
XSLFSlide createdSlide = slideShow.createSlide(slides[2].getSlideLayout());
//get content from slide to createdslide
createdSlide.importContent(slides[2]); 
//... add data to created slide

I have an error at line : createdSlide.importContent(slides[2]);

Caused by: java.lang.IllegalArgumentException: Relationship null doesn't start with this part /ppt/slides/slide3.xml
    at org.apache.poi.openxml4j.opc.PackagePart.getRelatedPart(PackagePart.java:468)
    at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:521)
    at org.apache.poi.xslf.usermodel.XSLFSlide.importContent(XSLFSlide.java:235)

P.S : this code works just fine with another tempalte. I need to use different templates based on user selection. (templates are stored in db as i'm using liferay).

I've searched for hours, but in vain! I don't even understand what the error means.

Any links/help would appreciated.


回答1:


The error comes from org.apache.poi.openxml4j.opc.PackagePart.getRelatedPart code line 468:

throw new IllegalArgumentException("Relationship " + rel + " doesn't start with this part " + _partName);.

The error states that rel is null. So org.apache.poi.xslf.usermodel.XSLFSheet.importBlip in code line 521:

blipPart = packagePart.getRelatedPart(blipRel);

had handed over blipRelas null. So org.apache.poi.xslf.usermodel.XSLFSlide.importContent in code line 235:

String relId = importBlip(blipId, src.getPackagePart());

had handed over blipId as null.

This is pretty clear if one of the pictures in your template in Slide 3 is not an embedded picture but a linked picture. The code:

@Override
public XSLFSlide importContent(XSLFSheet src){
    super.importContent(src);

    XSLFBackground bgShape = getBackground();
    if(bgShape != null) {
        CTBackground bg = (CTBackground)bgShape.getXmlObject();
        if(bg.isSetBgPr() && bg.getBgPr().isSetBlipFill()){
            CTBlip blip = bg.getBgPr().getBlipFill().getBlip();
            String blipId = blip.getEmbed();

            String relId = importBlip(blipId, src.getPackagePart());
            blip.setEmbed(relId);
        }
    }
    return this;
}

consideres only embedded blip data.

From your code lines I can see that you are using apache poi version 3.9. But as far as I see in current versions this had not changed until now. Only embedded bilp data will be considered.

So have a look at your template and make sure that all pictures are embedded and not linked.



来源:https://stackoverflow.com/questions/41877957/error-caused-by-java-lang-illegalargumentexception-relationship-null-doesnt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!