This article tells you how to judge that an element animation of PPT belongs to entry or exit or emphasis animation
According to the ECMA-376 document, in PPT animation, cTn, that is, the PresetClass attribute of the CommonTimeNode type defined by the OpenXML sdk, can be used to judge the current animation type
For example, create a new blank PPT file, put an element in it, and then set the fly in animation. At this time, the fly in animation is the enter animation. adopt Unzip document as folder tool Unzip this file and you can see it in slide1 XML has the following code
<p:cTn id="5" presetID="2" presetClass="entr" presetSubtype="4" fill="hold" grpId="0" nodeType="clickEffect">
The following code can be used for reading judgment
using var presentationDocument = DocumentFormat.OpenXml.Packaging.PresentationDocument.Open("Test.pptx", false); var presentationPart = presentationDocument.PresentationPart; var slidePart = presentationPart!.SlideParts.First(); var slide = slidePart.Slide; var timing = slide.Timing; // There is only one item in the first level by default var commonTimeNode = timing?.TimeNodeList?.ParallelTimeNode?.CommonTimeNode; if (commonTimeNode?.NodeType?.Value == TimeNodeValues.TmingRoot) { // This is in accordance with the agreement // nodeType="tmRoot" } if (commonTimeNode?.ChildTimeNodeList == null) return; // Theoretically, there is only one term, and it must be of type SequenceTimeNode var sequenceTimeNode = commonTimeNode.ChildTimeNodeList.GetFirstChild<SequenceTimeNode>(); var mainSequenceTimeNode = sequenceTimeNode.CommonTimeNode; if (mainSequenceTimeNode?.NodeType?.Value == TimeNodeValues.MainSequence) { // [timeline object (PowerPoint) | Microsoft docs]( https://docs.microsoft.com/zh-cn/office/vba/api/PowerPoint.TimeLine ) // MainSequence main animation sequence var mainParallelTimeNode = mainSequenceTimeNode.ChildTimeNodeList .GetFirstChild<ParallelTimeNode>().CommonTimeNode.ChildTimeNodeList .GetFirstChild<ParallelTimeNode>().CommonTimeNode.ChildTimeNodeList .GetFirstChild<ParallelTimeNode>(); switch (mainParallelTimeNode.CommonTimeNode.PresetClass.Value) { case TimeNodePresetClassValues.Entrance: // Enter animation break; case TimeNodePresetClassValues.Exit: // Exit animation break; case TimeNodePresetClassValues.Emphasis: // Emphasize animation break; case TimeNodePresetClassValues.Path: // Path animation break; case TimeNodePresetClassValues.Verb: break; case TimeNodePresetClassValues.MediaCall: // Play animation break; default: throw new ArgumentOutOfRangeException(); } }
All the code in this article github and gitee Welcome to visit
You can obtain the source code of this article in the following ways. First create an empty folder, then use the command line cd command to enter this empty folder, and enter the following code on the command line to obtain the code of this article
git init git remote add origin https://gitee.com/lindexi/lindexi_gd.git git pull origin f7c152959666fe9b6d543834fcb30a7ff6cf7e15
The above uses the source of gitee. If gitee cannot access it, please replace it with the source of github
git remote remove origin git remote add origin https://github.com/lindexi/lindexi_gd.git
After obtaining the code, enter the PptxDemo folder
To get emphasized courseware, please use git to switch to b8092ac9d12f315ae94ee2e53c3b4748d866b31b this commit to get the test Pptx with emphasis animation, the content is roughly as follows
<p:cTn id="5" presetID="25" presetClass="emph" presetSubtype="0" fill="hold" grpId="0" nodeType="clickEffect">
To get the courseware of path animation, please use git to switch to 08c7d7a13b19cfa120b7a9971f88da5af96b4c75 this commit to get the test Pptx has path animation. The content of path animation is as follows
<p:cTn id="5" presetID="42" presetClass="path" presetSubtype="0" accel="50000" decel="50000" fill="hold" grpId="0" nodeType="clickEffect"> <p:stCondLst> <p:cond delay="0" /> </p:stCondLst> <p:childTnLst> <p:animMotion origin="layout" path="M 0 0 L 0 0.25 E" pathEditMode="relative" ptsTypes=""> <p:cBhvr> <p:cTn id="6" dur="2000" fill="hold" /> <p:tgtEl> <p:spTgt spid="2" /> </p:tgtEl> <p:attrNameLst> <p:attrName>ppt_x</p:attrName> <p:attrName>ppt_y</p:attrName> </p:attrNameLst> </p:cBhvr> </p:animMotion> </p:childTnLst> </p:cTn>
To get the courseware for exiting animation, please use git to switch to 1521fdf2c9c94f13efe06dea25572e18847c11f3 this commit to get the test Pptx has exit animation. The content of exit animation is as follows:
<p:cTn id="5" presetID="16" presetClass="exit" presetSubtype="21" fill="hold" grpId="0" nodeType="clickEffect"> <p:stCondLst> <p:cond delay="0" /> </p:stCondLst> <p:childTnLst> <p:animEffect transition="out" filter="barn(inVertical)"> <p:cBhvr> <p:cTn id="6" dur="500" /> <p:tgtEl> <p:spTgt spid="2" /> </p:tgtEl> </p:cBhvr> </p:animEffect> <p:set> <p:cBhvr> <p:cTn id="7" dur="1" fill="hold"> <p:stCondLst> <p:cond delay="499" /> </p:stCondLst> </p:cTn> <p:tgtEl> <p:spTgt spid="2" /> </p:tgtEl> <p:attrNameLst> <p:attrName>style.visibility</p:attrName> </p:attrNameLst> </p:cBhvr> <p:to> <p:strVal val="hidden" /> </p:to> </p:set> </p:childTnLst> </p:cTn>
To obtain multimedia animation courseware, please use git to switch to 4338d948558f7748c865b47672d4a579dea8353c, and then you can get the test Pptx tape plays video animation. The content is as follows
<p:par> <p:cTn id="5" presetID="1" presetClass="mediacall" presetSubtype="0" fill="hold" nodeType="clickEffect"> <p:stCondLst> <p:cond delay="0" /> </p:stCondLst> <p:childTnLst> <p:cmd type="call" cmd="playFrom(0.0)"> <p:cBhvr> <p:cTn id="6" dur="1137" fill="hold" /> <p:tgtEl> <p:spTgt spid="3" /> </p:tgtEl> </p:cBhvr> </p:cmd> </p:childTnLst> </p:cTn> </p:par>
The attribute of this paper is to rely on dotnet OpenXML decompress document to folder tool This tool is an open source and free tool. Welcome to use it
This article will be updated frequently. Please read the original text: https://blog.lindexi.com/post/dotnet-OpenXML-%E8%AF%BB%E5%8F%96-PPT-%E5%8A%A8%E7%94%BB%E8%BF%9B%E5%85%A5%E9%80%80%E5%87%BA%E5%BC%BA%E8%B0%83%E5%8A%A8%E7%94%BB%E7%B1%BB%E5%9E%8B.html In order to avoid the misleading of old wrong knowledge and have a better reading experience.
This work adopts Knowledge sharing Attribution - non-commercial use - sharing in the same way 4.0 international license agreement License. Welcome to reprint, use and republish, but be sure to keep the signed Lin Dexi (including link: https://blog.lindexi.com ), shall not be used for commercial purposes, and the works modified based on this article must be distributed under the same license.