首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ApachePoi编辑presProps.xml文件

如何使用ApachePoi编辑presProps.xml文件
EN

Stack Overflow用户
提问于 2018-03-13 00:27:23
回答 1查看 131关注 0票数 1

我需要一个powerpoint循环,直到用户按下退出键。通过在powerpoint的幻灯片放映设置选项中选中“连续循环直到'ESC'”选项后保存并解压缩文件,我得到了更改的文件的差异(ppt/presProps.xml)。

未修复:

代码语言:javascript
复制
<p:presentationPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
   <p:showPr showNarration="1">
      <p:present />
      <p:sldAll />
      <p:penClr>
         <a:prstClr val="red" />
      </p:penClr>
      <p:extLst>
         <p:ext uri="{EC167BDD-8182-4AB7-AECC-EB403E3ABB37}">
            <p14:laserClr xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main">
               <a:srgbClr val="FF0000" />
            </p14:laserClr>
         </p:ext>
         <p:ext uri="{2FDB2607-1784-4EEB-B798-7EB5836EED8A}">
            <p14:showMediaCtrls xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="1" />
         </p:ext>
      </p:extLst>
   </p:showPr>
   <p:extLst>
      <p:ext uri="{E76CE94A-603C-4142-B9EB-6D1370010A27}">
         <p14:discardImageEditData xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="0" />
      </p:ext>
      <p:ext uri="{D31A062A-798A-4329-ABDD-BBA856620510}">
         <p14:defaultImageDpi xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="220" />
      </p:ext>
      <p:ext uri="{FD5EFAAD-0ECE-453E-9831-46B23BE46B34}">
         <p15:chartTrackingRefBased xmlns:p15="http://schemas.microsoft.com/office/powerpoint/2012/main" val="0" />
      </p:ext>
   </p:extLst>
</p:presentationPr>

已修复:

代码语言:javascript
复制
<p:presentationPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
   <p:showPr loop="1" showNarration="1">
      <p:present />
      <p:sldAll />
      <p:penClr>
         <a:prstClr val="red" />
      </p:penClr>
      <p:extLst>
         <p:ext uri="{EC167BDD-8182-4AB7-AECC-EB403E3ABB37}">
            <p14:laserClr xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main">
               <a:srgbClr val="FF0000" />
            </p14:laserClr>
         </p:ext>
         <p:ext uri="{2FDB2607-1784-4EEB-B798-7EB5836EED8A}">
            <p14:showMediaCtrls xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="1" />
         </p:ext>
      </p:extLst>
   </p:showPr>
   <p:extLst>
      <p:ext uri="{E76CE94A-603C-4142-B9EB-6D1370010A27}">
         <p14:discardImageEditData xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="0" />
      </p:ext>
      <p:ext uri="{D31A062A-798A-4329-ABDD-BBA856620510}">
         <p14:defaultImageDpi xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="220" />
      </p:ext>
      <p:ext uri="{FD5EFAAD-0ECE-453E-9831-46B23BE46B34}">
         <p15:chartTrackingRefBased xmlns:p15="http://schemas.microsoft.com/office/powerpoint/2012/main" val="0" />
      </p:ext>
   </p:extLst>
</p:presentationPr>

元素差异:

代码语言:javascript
复制
3c3
<    <p:showPr showNarration="1">
---
>    <p:showPr loop="1" showNarration="1">

它看起来像是在presentation元素中的p元素上,但是我不知道如何在POI中设置该属性。

EN

回答 1

Stack Overflow用户

发布于 2018-03-13 07:32:32

这只是一个快速的技巧,以显示包部分的修改,这些修改不能通过API访问。由于XmlBeans将循环属性设置为"true"而不是"1",因此可能需要通过XmlCursor API设置它。

代码语言:javascript
复制
public static void main(String[] args) throws Exception {
    OPCPackage opc = OPCPackage.open("headers.pptx", PackageAccess.READ_WRITE);
    try (XMLSlideShow ppt = new XMLSlideShow(opc)) {
        PackagePart presProps = ppt.getPackage().getPart(PackagingURIHelper.createPartName("/ppt/presProps.xml"));
        PresentationPrDocument doc = PresentationPrDocument.Factory.parse(presProps.getInputStream());
        CTPresentationProperties pr = doc.getPresentationPr();
        CTShowProperties showPr = pr.isSetShowPr() ? pr.getShowPr() : pr.addNewShowPr();
        showPr.setLoop(true);
        presProps.clear();
        try (OutputStream os = presProps.getOutputStream()) {
            doc.save(os);
        }
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49240059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档