错误:由以下原因引起:java.lang.IllegalArgumentException:关系空值不以此部分/ppt/slides/slide3.xml开头 [英] ERROR : Caused by: java.lang.IllegalArgumentException: Relationship null doesn't start with this part /ppt/slides/slide3.xml

查看:29
本文介绍了错误:由以下原因引起:java.lang.IllegalArgumentException:关系空值不以此部分/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).

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 + " 不以这部分开头 " + _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 交为 null.

had handed over blipId as null.

如果幻灯片 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:关系空值不以此部分/ppt/slides/slide3.xml开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆