none
How to work with with Power point Notes pane with open xml ?

    Question

  • Hi,

    I am working with OpenXml for Powerpoint with .net framework, I have accomplished to create slides and input data into them using them.

    The problem i am encountering is with the Notes pane in powerpoint (Under each slide). I want to post some data into it. Can anyone help me on understanding the object model and inserting data into the notes pane using .net.

    Thanks,

    Sravan

    Tuesday, August 13, 2013 7:44 PM

Answers

All replies

  • Hello Sravankumar Karanam,

    Welcome toMSDN Support Forum.

    From your description, I notice the issue you are experiencing is that how to read and write the notes of the PPT with .net.

    As far as I know, we can operate PPT using components provided by Microsoft.

    I made a sample and please see the sample code below:

    using Microsoft.Office.Core;
    using Microsoft.Office.Interop.PowerPoint;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    namespace ODBC
    {
        public partial class OperatePPT : Form
        {
            public OperatePPT()
            {
                InitializeComponent();
                string fullname = "E:\\BMX\\Lab\\SmapleFile\\Presentation3.pptx";     //File Path
                Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation pptObject = pptApp.Presentations.Open(fullname, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                string doc = "";
                string note = string.Empty;
                foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in pptObject.Slides)
                {
                    foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.NotesPage.Shapes)
                    {
                        if (shape.Type == MsoShapeType.msoPlaceholder)
                        {
                            if (shape.PlaceholderFormat.Type == PpPlaceholderType.ppPlaceholderBody)
                            {
                                //note += shape.TextFrame.TextRange.Text.ToString() + "\n";//Get the ntoes.
                                shape.TextFrame.TextRange.Text = shape.TextFrame.TextRange.Text + " BMX";//Modify the notes.
                            }
                        }
                    }
                }
                pptObject.Save();
                pptObject.Close();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pptObject);
                pptObject = null;
                pptApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp);
                pptApp = null;
                this.label1.Text = note;
            }
        }
    }

    My PPT notes:

    The Result:

    In the sample I modifyed the “Hello” to "Hell BMX".

    And to use components you should quote namespaces as follow:

    1. Microsoft.Office.Core;
    2. Microsoft.Office.Interop.PowerPoint;

    If this is not helpful to you, please let me know.

    I look forward to hearing from you.

    Best Regards.


    Fred Bao
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Friday, August 16, 2013 5:13 AM
  • Thanks for the reply, this is Samantha DeNelle the other developer assigned to this task, but we cannot use the interop functionality to complete this. So far we have successfully creates the Notesslide object and saved it. The issue that we are facing is trying to attach that notes slide back to the presentation object. We have a template we start with, then clone that object and delete the original object. However when we do so we lose the notes that were associated. It seems that the clone slide we are using only clones the slidepart but not the relationship between the note we created and the slide (clone). Code example below

      using (var presentationDocument = PresentationDocument.Open(destinationFile, true))
                {
                    var presentationPart = presentationDocument.PresentationPart;
                    var slideIds = presentationPart.Presentation.SlideIdList.ChildElements;
                    string relId = ((SlideId)slideIds[0]).RelationshipId;    
                    var slideTemplate = (SlidePart)presentationPart.GetPartById(relId);
                    // Insert a slide for each coverage plan   
                    var i = One;
                    foreach (var item in items)
                    {

                        foreach (NotesSlidePart notes in presentationPart.SlideParts.Select(slide => slide.NotesSlidePart))
                        {
                            CreateNotes(notes);
                            //presentationPart.NotesMasterPart.AddPart(notes);
                            //presentationPart.NotesMasterPart.SlidePart.Slide.Save();
                        }
                        var newSlide = CloneSlide(presentationPart, slideTemplate, i);
                            PopulateSlide(newSlide, item, dispEst, dispActual, presentationPart, i, Data);
                            newSlide.Slide.Save();
                            i++;
                        
                    }

                    DeleteSlide(presentationDocument, Zero);
                    presentationPart.Presentation.Save();
                }

    Any help would be greqatly appriciated as we have invested too many hours at this point and the deadline is rapidly approaching.

    Thanks in advance,

    Samantha

    Friday, August 16, 2013 12:41 PM
  • Hello Samantha DeNelle,

    I am so sorry that I ignore that you are using OpenXMl, but I gave a solution with PIA.

    Actually the problem which you are experiencing are more related with Office Dev.

    So I suggest you can post your problem to:

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=oxmlsdk.

    There you can find an expert to help you solve the problem better.

    Thanks for your understanding.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Monday, August 19, 2013 2:48 AM