question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug with Open XML SDK: PowerPoint could not open the file created by v2.18 with mc:AlternateContent element

See original GitHub issue

Describe the bug The customer generated PPTX documents by using OpenXML SDK, but PowerPoint would prompt Repair dialog while opening the document, and part of slide layout would be missed. This issue was not there when using OpenXML SDK 2.7.2 until upgraded OpenXML SDK to version 2.11~2.18.

Screenshots image

To Reproduce

Steps to reproduce the behavior:

  1. Use following code, to generate a new pptx file.
public static SlideLayoutPart CreateSlideLayout(PackEngineContext packEngineContext, SlideLayoutPart sourceLayoutPart, PresentationDocument targetDoc, SlideMasterPart targetMasterPart, List<ImageCacheItem> imageCacheItems, PPTIdCounter pptIdCounter)
{
    SlideLayoutPart targetLayoutPart = targetMasterPart.AddNewPart<SlideLayoutPart>();
    targetLayoutPart.FeedData(sourceLayoutPart);

    if (targetMasterPart.IsRepeatNameOfSlideLayout(targetLayoutPart))
    {
        targetLayoutPart.SetNameofSlideLayout();
    }

    targetLayoutPart.AddPart(targetMasterPart, targetDoc.PresentationPart.GetIdOfPart(targetMasterPart));

    bool needCloneDiagramParts = (sourceLayoutPart.DiagramColorsParts != null && sourceLayoutPart.DiagramColorsParts.Count() > 0) ||
                                  (sourceLayoutPart.DiagramDataParts != null && sourceLayoutPart.DiagramDataParts.Count() > 0);
    bool needCloneChartParts = sourceLayoutPart.HasChart();
    AddImageRelatedParts(sourceLayoutPart, sourceLayoutPart.SlideLayout.CommonSlideData, sourceLayoutPart.VmlDrawingParts,
                 targetLayoutPart, imageCacheItems, needCloneDiagramParts, needCloneChartParts);
    HandleOtherParts(packEngineContext, sourceLayoutPart, sourceLayoutPart.SlideLayout.CommonSlideData,
                 targetDoc, targetLayoutPart, targetLayoutPart.SlideLayout.CommonSlideData);

    SlideLayoutId newLayoutId = new SlideLayoutId();
    newLayoutId.Id = pptIdCounter.GetNextSlideMasterLayoutId();
    newLayoutId.RelationshipId = targetMasterPart.GetIdOfPart(targetLayoutPart);
    targetMasterPart.SlideMaster.SlideLayoutIdList.Append(newLayoutId);
    targetLayoutPart.SlideLayout.Save();

    return targetLayoutPart;
}

Observed behavior PowerPoint will pop up repair error message when opening the error.pptx.

Expected behavior No repair prompt and slide layout would not be broken.

Desktop (please complete the following information):

  • OS: Windows
  • Office version 16.0.15726.20202
  • .NET Target: .NET Core
  • DocumentFormat.OpenXml Version: 2.18.0

Additional context

  1. We compared the normal.pptx and error.pptx, then found the element order is different, if we manually change the element order, then PowerPoint can open the file successfully.

  2. The following code came from the directory &\ppt\slideMasters\slideMaster1.xml, XML node in PPTX generated by openxml2.7.2 is as follows, the element AlternateContent was behind sldLayoutIdLst, and the document can be opened normally. image

  3. In version 2.11~2.18 of OpenXML, the generated XML document changed to such that the “AlternateContent” and “p:sldLayoutIdLst” were reversed, causing this problem. image

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:19

github_iconTop GitHub Comments

2reactions
mahongbo86commented, Nov 16, 2022

I will provide a fully reproducible demo of the problem, but it will take a while, I will update it here when I am done

2reactions
mahongbo86commented, Nov 16, 2022

@tomjebo source.pptx target.pptx These two pptx files can be provided, and the target has the problem of this error prompt.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with presentations (Open XML SDK)
Use the Open XML SDK to programmatically create Office Word, Excel, and PowerPoint documents, and manipulate their content.
Read more >
Create a presentation document by providing a file name ...
Use the Open XML SDK to programmatically create Office Word, Excel, and PowerPoint documents, and manipulate their content.
Read more >
Word App Unable to Open (Office Open XML Document . ...
I need to open some .docx files on Google Drive and when I try to do so, at first a message would pop...
Read more >
Working with presentation slides (Open XML SDK)
Use the Open XML SDK to programmatically create Office Word, Excel, and PowerPoint documents, and manipulate their content.
Read more >
Working with notes slides (Open XML SDK)
Use the Open XML SDK to programmatically create Office Word, Excel, and PowerPoint documents, and manipulate their content.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found