Skip to content

Powerpoint: slide transition after x milliseconds causing audio not to be played AND transition to be stalled #1875

Open
@steamonimo

Description

@steamonimo

Describe the bug
My code repeatedly works on the same powerpoint file.

-My code attaches MP3 audio
-My code attaches playfrom timing to play automatically
-My code attaches transition to next slide after x milliseconds

The transition seems to cause the XML to be malformed. After saving the resulting file in PowerPoint, closing the file and reopening the timing and transition are not executed anymore as if they do not exist.

To Reproduce

public static void AddTransitionAfterMilliseconds(SlidePart slidePart, long milliseconds)
{
    // Create a new Transition element.
    Transition transition = new Transition();
    transition.AdvanceAfterTime = milliseconds.ToString(); // time in milliseconds
    transition.AdvanceOnClick = false; // do not allow click to advance

    CommonSlideData commonSlideData = slidePart.Slide.CommonSlideData!;

    // Check for an existing transition and remove it if present.
    var transitions = commonSlideData.Elements<Transition>().ToList();
    foreach (var tr in transitions)
    {
        tr.Remove();
    }

    transitions = slidePart.Slide.Elements<Transition>().ToList();
    foreach (var tr in transitions)
    {
        tr.Remove();
    }

    var alternateContents = slidePart.Slide.Descendants<AlternateContent>().ToList();

    foreach (var altContent in alternateContents)
    {
        transitions = altContent.Elements<Transition>().ToList();

        foreach (var tr in transitions)
        {
            tr.Remove();
        }
    }

    // Append the transition element to CommonSlideData.
    commonSlideData.Append(transition);

    slidePart.Slide.Save();
}

Steps to reproduce the behavior:

  1. apply the transition with the previous code

Observed behavior
Structure of slide.xml is malformed

Expected behavior
After opening and saving with newest PowerPoint (this causes structural changes) the audio are still played and transition executed.

Desktop (please complete the following information):

  • OS: [e.g. Windows]
  • Office version: Microsoft® PowerPoint® für Microsoft 365 MSO (Version 2501 Build 16.0.18429.20132) 64 Bit
  • .NET Target: .NET core 8.0.13
  • DocumentFormat.OpenXml Version: 3.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions