none
Problem with PresentationML and PowerPoint 2007 RRS feed

  • Question

  • Cheers,

    I'm getting crazy with an issue. I'm creating presentations dinamicaly (by c# code) using OpenXML SDK 2.0 and i'm getting the following behavior:

    When I add a new slide into the presentation and try to open it in PowerPoint, Powerpoint complains and tries to repair my file. Powerpoint 2010 repairs it and all the contents is there.  OK.

    Powerpoint 2007 also complains, tries to repair the file and after that, the content is missing for all slides (except for the first one!)

    I didn't get any validation errors when i submit the file to OpenXmlValidator object.

     

     

     

     

     

     

    Additional information

     

    I've created a presentation using Open XML 2.0 SDK, in fact i've created a full document library that is able to output reports using ooxml formats.
    When i insert a new slide into a presentation, i validate the document and it doesn't show any validation issues (no missing objects, no missing data, no unexpected elements at all)
    the behavior is:
    When i insert texts, shapes or any element into a presentation file into a single slide, PowerPoint Viewer 2007 is able to open the generated presentation.
    If i create a blank presentation with two slides (no contents) Powerpoint 2007 isn't able to open the presentation. When i try to open it with Powerpoint 2010, the application (PowerPoint) attempts to repair the file and then it opens.
    If i add any content into the second slide, the behavior is the same. I'm generating unique relids for the elements that requires it.
    When i try to open the slide with contents in PowerPoint 2007, it attempts to repair the file as well, but the content for the slides (except for the first one) is lost.

    I've tryed to redo the Insertslide function as explained at the SDK documentation but the behavior is the same.

    When i compare the repaired file, it creates clones of the generated xml files and changes its relationships - it happens only in PowerPoint 2010.
    If i repair the file, all contents is removed from the slide 2 and above.

    I did several changes inside my code. If i follow the instructions of the SDK documentation, it generates a set of validation issues on OpenXMLValidator.

    I have this issue only on PresentationML part of SDK.
    Word and Excel output work as expected.

    There are any known issue regarding the PresentationML generated file on the SDK or it wasn't yet mentionend on any support ticket?

    Thanks a lot.

     

     

     


    Mauro Zamaro .:
    • Edited by Mauro Zamaro Friday, October 21, 2011 6:38 PM Additional information
    Thursday, October 20, 2011 6:50 PM

Answers

  • HI Mauro,

    After a long comparision between your code snippet with the code no the article:

    http://msdn.microsoft.com/en-us/library/cc850834.aspx#Y1999

    I found that you need to change the following statements:

    1. change

    slide.CommonSlideData.ShapeTree.AppendChild(new DocumentFormat.OpenXml.Office.Drawing.GroupShapeProperties());


     to be

                slide.CommonSlideData.ShapeTree.AppendChild(new GroupShapeProperties());
    

    2. change

                bodyShape.NonVisualShapeProperties = new NonVisualShapeProperties(new DocumentFormat.OpenXml.Drawing.NonVisualDrawingProperties() { Id = drawingObjectId, Name = "Content Placeholder" },
                                                                     new NonVisualShapeDrawingProperties(new Drawing.ShapeLocks() { NoGrouping = true }),
                                                                     new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Index = 1 }));

    to be

                bodyShape.NonVisualShapeProperties = new NonVisualShapeProperties(new NonVisualDrawingProperties() { Id = drawingObjectId, Name = "Content Placeholder" },
                                                                     new NonVisualShapeDrawingProperties(new Drawing.ShapeLocks() { NoGrouping = true }),
                                                                     new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Index = 1 }));
    

    You need to remove the DocumentFormat.OpenXml.Office.Drawing and DocumentFormat.OpenXml.Drawing.

    Please try again after you make these changes. The code on the article works for me on my side.

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Bruce Song Monday, October 24, 2011 9:55 AM
    • Marked as answer by Mauro Zamaro Monday, October 24, 2011 1:21 PM
    Monday, October 24, 2011 9:54 AM

All replies

  • I've tested the following code.. and it doesn't work

     

     

    public class Presentation
        {
            // <summary>
            // Insert a slide into the specified presentation.
            // </summary>
            // <param name="presentationFile">The presentation file.</param>
            // <param name="position">The zero-based position of the new slide.</param>
            // <param name="slideTitle">The title of the new slide.</param>
            public static void InsertNewSlide(string presentationFile, int position, string slideTitle)
            {
    
                // Open the source document as read/write. 
                using (PresentationDocument presentationDocument = PresentationDocument.Open(presentationFile, true))
                {
                    // Pass the source document and the position and title of the slide to be inserted to the next method.
                    InsertNewSlide(presentationDocument, position, slideTitle);
                }
            }
            
            // <summary>
            // Insert the specified slide into the presentation at the specified position.
            // </summary>
            // <param name="presentationDocument">The presentation document.</param>
            // <param name="position">The zero-based position of the new slide.</param>
            // <param name="slideTitle">The title of the new slide.</param>
            public static void InsertNewSlide(PresentationDocument presentationDocument, int position, string slideTitle)
            {
                if (presentationDocument == null)
                {
                    throw new ArgumentNullException("presentationDocument");
                }
    
                if (slideTitle == null)
                {
                    throw new ArgumentNullException("slideTitle");
                }
    
                PresentationPart presentationPart = presentationDocument.PresentationPart;
    
                // Verify that the presentation is not empty.
                if (presentationPart == null)
                {
                    throw new InvalidOperationException("The presentation document is empty.");
                }
    
                // Declare and instantiate a new slide.
                Slide slide = new Slide(new CommonSlideData(new ShapeTree()));
                uint drawingObjectId = 1;
    
                // Construct the slide content.            
                // Specify the non-visual properties of the new slide.
                NonVisualGroupShapeProperties nonVisualProperties = slide.CommonSlideData.ShapeTree.AppendChild(new NonVisualGroupShapeProperties());
                nonVisualProperties.NonVisualDrawingProperties = new NonVisualDrawingProperties() { Id = 1, Name = "" };
                nonVisualProperties.NonVisualGroupShapeDrawingProperties = new NonVisualGroupShapeDrawingProperties();
                nonVisualProperties.ApplicationNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties();
    
                // Specify the group shape properties of the new slide.
                slide.CommonSlideData.ShapeTree.AppendChild(new DocumentFormat.OpenXml.Office.Drawing.GroupShapeProperties());
                            // Declare and instantiate the title shape of the new slide.
                Shape titleShape = slide.CommonSlideData.ShapeTree.AppendChild(new Shape());
    
                drawingObjectId++;
    
                // Specify the required shape properties for the title shape. 
                titleShape.NonVisualShapeProperties = new NonVisualShapeProperties(new NonVisualDrawingProperties() { Id = drawingObjectId, Name = "Title" },
                                                                     new NonVisualShapeDrawingProperties(new Drawing.ShapeLocks() { NoGrouping = true }),
                                                                     new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Type = PlaceholderValues.Title }));
                titleShape.ShapeProperties = new ShapeProperties();
    
                // Specify the text of the title shape.
                titleShape.TextBody = new TextBody(new Drawing.BodyProperties(),
                                                   new Drawing.ListStyle(),
                                                   new Drawing.Paragraph(new Drawing.Run(new Drawing.Text() { Text = slideTitle })));
                            // Declare and instantiate the body shape of the new slide.
                Shape bodyShape = slide.CommonSlideData.ShapeTree.AppendChild(new Shape());
                drawingObjectId++;
    
                // Specify the required shape properties for the body shape.
                bodyShape.NonVisualShapeProperties = new NonVisualShapeProperties(new DocumentFormat.OpenXml.Drawing.NonVisualDrawingProperties() { Id = drawingObjectId, Name = "Content Placeholder" },
                                                                     new NonVisualShapeDrawingProperties(new Drawing.ShapeLocks() { NoGrouping = true }),
                                                                     new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Index = 1 }));
                bodyShape.ShapeProperties = new ShapeProperties();
    
                // Specify the text of the body shape.
                bodyShape.TextBody = new TextBody(new Drawing.BodyProperties(),
                                                  new Drawing.ListStyle(),
                                                  new Drawing.Paragraph());
                // Create the slide part for the new slide.
                SlidePart slidePart = presentationPart.AddNewPart<SlidePart>();
    
                // Save the new slide part.
                slide.Save(slidePart);
    
                // Modify the slide ID list in the presentation part.
                // The slide ID list should not be null.
                SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;
    
                // Find the highest slide ID in the current list.
                uint maxSlideId = 1;
                SlideId prevSlideId = null;
    
                foreach (SlideId slideId in slideIdList.ChildElements)
                {
                    if (slideId.Id > maxSlideId)
                    {
                        maxSlideId = slideId.Id;
                    }
    
                    position--;
                    if (position == 0)
                    {
                        prevSlideId = slideId;
                    }
    
                }
    
                maxSlideId++;
    
                // Get the ID of the previous slide.
                SlidePart lastSlidePart;
    
                if (prevSlideId != null)
                {
                    lastSlidePart = (SlidePart)presentationPart.GetPartById(prevSlideId.RelationshipId);
                }
                else
                {
                    lastSlidePart = (SlidePart)presentationPart.GetPartById(((SlideId)(slideIdList.ChildElements[0])).RelationshipId);
                }
    
    
                // Use the same slide layout as that of the previous slide.
                if (null != lastSlidePart.SlideLayoutPart)
                {
                    slidePart.AddPart(lastSlidePart.SlideLayoutPart);
                }
    
                // Insert the new slide into the slide list after the previous slide.
                SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);
                newSlideId.Id = maxSlideId;
                newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart);
    
                // Save the modified prsentation.
                presentationPart.Presentation.Save();
            }
        }
    

    (i've copied it from the SDK Help file)

     

    Anyone can help me?


    Mauro Zamaro .:
    Thursday, October 20, 2011 7:40 PM
  • HI Mauro,

    After a long comparision between your code snippet with the code no the article:

    http://msdn.microsoft.com/en-us/library/cc850834.aspx#Y1999

    I found that you need to change the following statements:

    1. change

    slide.CommonSlideData.ShapeTree.AppendChild(new DocumentFormat.OpenXml.Office.Drawing.GroupShapeProperties());


     to be

                slide.CommonSlideData.ShapeTree.AppendChild(new GroupShapeProperties());
    

    2. change

                bodyShape.NonVisualShapeProperties = new NonVisualShapeProperties(new DocumentFormat.OpenXml.Drawing.NonVisualDrawingProperties() { Id = drawingObjectId, Name = "Content Placeholder" },
                                                                     new NonVisualShapeDrawingProperties(new Drawing.ShapeLocks() { NoGrouping = true }),
                                                                     new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Index = 1 }));

    to be

                bodyShape.NonVisualShapeProperties = new NonVisualShapeProperties(new NonVisualDrawingProperties() { Id = drawingObjectId, Name = "Content Placeholder" },
                                                                     new NonVisualShapeDrawingProperties(new Drawing.ShapeLocks() { NoGrouping = true }),
                                                                     new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Index = 1 }));
    

    You need to remove the DocumentFormat.OpenXml.Office.Drawing and DocumentFormat.OpenXml.Drawing.

    Please try again after you make these changes. The code on the article works for me on my side.

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Bruce Song Monday, October 24, 2011 9:55 AM
    • Marked as answer by Mauro Zamaro Monday, October 24, 2011 1:21 PM
    Monday, October 24, 2011 9:54 AM
  • Hi Bruce,

    The code with the substitutions you had suggested worked very fine. Now i'll try to apply to my framework because there's some functionalities i need to apply on that.

    It worked! :) it's the most important thing. Now i've learned what i was doing wrong.

    Thanks a lot,

    Best regards.


    Mauro Zamaro .:
    Monday, October 24, 2011 1:21 PM