本文介绍了错误:由以下原因引起:java.lang.IllegalArgumentException:关系null并非从此部分开始/ppt/slides/slide3.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与apache poi xslf一起导出ppt文件.首先,我有一个包含3张幻灯片的模板集:标题幻灯片,摘要幻灯片和第三张幻灯片

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.

因此,要这样做:

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

我在第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:此代码与另一个临时模板一起使用也很好.我需要根据用户选择使用不同的模板. (模板在我使用liferay时存储在db中).

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.

推荐答案

错误来自 org.apache.poi .openxml4j.opc.PackagePart.getRelatedPart 代码行468:

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);.

错误指出rel为空.因此 org.apache.poi.xslf.usermodel.XSLFSheet.importBlip 在代码中第521行:

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

blipPart = packagePart.getRelatedPart(blipRel);

已将blipRel移交为空.因此 org.apache.poi.xslf.usermodel.XSLFSlide.importContent 在代码行235:

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

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

已将blipId移交为空.

如果幻灯片3中模板中的图片之一不是嵌入式图片而是链接的图片,则这很清楚.代码:

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;
}

仅考虑嵌入的blip数据.

consideres only embedded blip data.

从您的代码行中,我可以看到您正在使用apache poi版本3.9.但是据我目前的版本来看,这一直没有改变.仅考虑嵌入的Bilp数据.

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.

这篇关于错误:由以下原因引起:java.lang.IllegalArgumentException:关系null并非从此部分开始/ppt/slides/slide3.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 07:04