/// <summary>
        /// Clones this slide.
        /// </summary>
        /// <returns>The clone.</returns>
        /// <remarks>
        /// <see href="http://blogs.msdn.com/b/brian_jones/archive/2009/08/13/adding-repeating-data-to-powerpoint.aspx">Adding Repeating Data to PowerPoint</see>
        /// <see href="http://startbigthinksmall.wordpress.com/2011/05/17/cloning-a-slide-using-open-xml-sdk-2-0/">Cloning a Slide using Open Xml SDK 2.0</see>
        /// <see href="http://www.exsilio.com/blog/post/2011/03/21/Cloning-Slides-including-Images-and-Charts-in-PowerPoint-presentations-Using-Open-XML-SDK-20-Productivity-Tool.aspx">See Cloning Slides including Images and Charts in PowerPoint presentations and Using Open XML SDK 2.0 Productivity Tool</see>
        /// </remarks>
        public PowerpointSlide Clone()
        {
            SlidePart slideTemplate = this.slidePart;

            // Clone slide contents
            SlidePart slidePartClone = this.presentationPart.AddNewPart <SlidePart>();

            using (var templateStream = slideTemplate.GetStream(FileMode.Open))
            {
                slidePartClone.FeedData(templateStream);
            }

            // Copy layout part
            slidePartClone.AddPart(slideTemplate.SlideLayoutPart);

            // Copy the image parts
            foreach (ImagePart image in slideTemplate.ImageParts)
            {
                ImagePart imageClone = slidePartClone.AddImagePart(image.ContentType, slideTemplate.GetIdOfPart(image));
                using (var imageStream = image.GetStream())
                {
                    imageClone.FeedData(imageStream);
                }
            }

            return(new PowerpointSlide(this.presentationPart, slidePartClone));
        }
Example #2
0
        private Slide insertSlide(PresentationPart presentationPart, string layoutName)
        {
            UInt32          slideId         = 256U;
            var             slideIdList     = presentationPart.Presentation.SlideIdList;
            SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.First();
            SlideLayoutPart slideLayoutPart = slideMasterPart.SlideLayoutParts.First();

            if (slideIdList == null)
            {
                presentationPart.Presentation.SlideIdList = new SlideIdList();
                slideIdList = presentationPart.Presentation.SlideIdList;
            }

            slideId += Convert.ToUInt32(slideIdList.Count());
            Slide     slide     = new Slide(new CommonSlideData(new ShapeTree()));
            SlidePart slidePart = presentationPart.AddNewPart <SlidePart>();

            slide.Save(slidePart);

            slidePart.AddPart <SlideLayoutPart>(slideLayoutPart);
            slidePart.Slide.CommonSlideData = (CommonSlideData)slideLayoutPart.SlideLayout.CommonSlideData.Clone();
            SlideId newSlideId = presentationPart.Presentation.SlideIdList.AppendChild <SlideId>(new SlideId());

            newSlideId.Id             = slideId;
            newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart);

            return(getSlideByRelationShipId(presentationPart, newSlideId.RelationshipId));
        }
Example #3
0
        internal static Slide InsertSlide(this PresentationPart presentationPart, string layoutName)
        {
            UInt32 slideId = 256U;

            slideId += Convert.ToUInt32(presentationPart.Presentation.SlideIdList.Count());

            Slide slide = new Slide(new CommonSlideData(new ShapeTree()));

            SlidePart sPart = presentationPart.AddNewPart <SlidePart>();

            slide.Save(sPart);

            SlideMasterPart smPart = presentationPart.SlideMasterParts.First();
            SlideLayoutPart slPart = smPart.SlideLayoutParts.SingleOrDefault
                                         (sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName));

            if (slPart == null)
            {
                throw new Exception("The slide layout " + layoutName + " is not found");
            }
            sPart.AddPart <SlideLayoutPart>(slPart);

            sPart.Slide.CommonSlideData = (CommonSlideData)smPart.SlideLayoutParts.SingleOrDefault(
                sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName)).SlideLayout.CommonSlideData.Clone();

            SlideId newSlideId = presentationPart.Presentation.SlideIdList.AppendChild <SlideId>(new SlideId());

            newSlideId.Id             = slideId;
            newSlideId.RelationshipId = presentationPart.GetIdOfPart(sPart);

            return(GetSlideByRelationshipId(presentationPart, newSlideId.RelationshipId));
        }
        private SlidePart CloneSlidePart(PresentationPart presentationPart, SlidePart slideTemplate)
        {
            SlidePart cloneSlidei = presentationPart.AddNewPart <SlidePart>("newSlide" + i);

            i++;
            cloneSlidei.FeedData(slideTemplate.GetStream(FileMode.Open));
            cloneSlidei.AddPart(slideTemplate.SlideLayoutPart);

            SlideIdList slideidlist = presentationPart.Presentation.SlideIdList;
            uint        maxide      = 0;
            SlideId     beforeSlide = null;

            foreach (SlideId slideidw in slideidlist.ChildElements)
            {
                if (slideidw.Id > maxide)
                {
                    beforeSlide = slideidw;
                    maxide      = slideidw.Id;
                }
            }
            maxide++;
            SlideId inside = slideidlist.InsertAfter(new SlideId(), beforeSlide);

            inside.Id             = maxide;
            inside.RelationshipId = presentationPart.GetIdOfPart(cloneSlidei);
            return(cloneSlidei);
        }
 public void Create()
 {
     NewSlidePart = _doc.PresentationPart.AddNewPart <SlidePart>(NewSlideName + _slideId++);
     //copy the contents of the template slide to the new slide and attach the appropriate layout
     NewSlidePart.FeedData(_teplateSlide.GetStream(FileMode.Open));
     NewSlidePart.AddPart(_teplateSlide.SlideLayoutPart,
                          _teplateSlide.GetIdOfPart(_teplateSlide.SlideLayoutPart));
 }
Example #6
0
        //http://stackoverflow.com/questions/32076114/c-sharp-openxml-sdk-2-5-insert-new-slide-from-slide-masters-with-the-layout
        public static SlidePart AppendNewSlide(PresentationPart presentationPart, SlideLayoutPart masterLayoutPart, out IEnumerable <Shape> placeholderShapes)
        {
            Slide clonedSlide = new Slide()
            {
                ColorMapOverride = new ColorMapOverride {
                    MasterColorMapping = new Draw.MasterColorMapping()
                }
            };

            SlidePart clonedSlidePart = presentationPart.AddNewPart <SlidePart>();

            clonedSlidePart.Slide = clonedSlide;
            clonedSlidePart.AddPart(masterLayoutPart);
            clonedSlide.Save(clonedSlidePart);

            var masterShapeTree = masterLayoutPart.SlideLayout.CommonSlideData.ShapeTree;

            placeholderShapes = (from s in masterShapeTree.ChildElements <Shape>()
                                 where s.NonVisualShapeProperties.OfType <ApplicationNonVisualDrawingProperties>().Any(anvdp => anvdp.PlaceholderShape != null)
                                 select new Shape()
            {
                NonVisualShapeProperties = (NonVisualShapeProperties)s.NonVisualShapeProperties.CloneNode(true),
                TextBody = new TextBody(s.TextBody.ChildElements <Draw.Paragraph>().Select(p => p.CloneNode(true)))
                {
                    BodyProperties = new Draw.BodyProperties(),
                    ListStyle = new Draw.ListStyle()
                },
                ShapeProperties = new ShapeProperties()
            }).ToList();

            clonedSlide.CommonSlideData = new CommonSlideData
            {
                ShapeTree = new ShapeTree(placeholderShapes)
                {
                    GroupShapeProperties          = (GroupShapeProperties)masterShapeTree.GroupShapeProperties.CloneNode(true),
                    NonVisualGroupShapeProperties = (NonVisualGroupShapeProperties)masterShapeTree.NonVisualGroupShapeProperties.CloneNode(true)
                }
            };

            SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;

            // Find the highest slide ID in the current list.
            uint maxSlideId = slideIdList.Max(c => (uint?)((SlideId)c).Id) ?? 256;

            // Insert the new slide into the slide list after the previous slide.
            slideIdList.Append(new SlideId()
            {
                Id             = ++maxSlideId,
                RelationshipId = presentationPart.GetIdOfPart(clonedSlidePart)
            });
            //presentationPart.Presentation.Save();

            return(clonedSlidePart);
        }
        public SlidePart CloneInputSlide()
        {
            if (Presentation == null)
            {
                throw new ArgumentNullException("presentationDocument");
            }

            PresentationPart presentationPart = Presentation.PresentationPart;

            SlideId slideId = presentationPart.Presentation.SlideIdList.GetFirstChild <SlideId>();

            string relId = slideId.RelationshipId;

            // Get the slide part by the relationship ID.

            SlidePart inputSlide = (SlidePart)presentationPart.GetPartById(relId);

            if (inputSlide == default(SlidePart))
            {
                throw new ArgumentException("SlidePart");
            }
            //Create a new slide part in the presentation.
            SlidePart newSlidePart = presentationPart.AddNewPart <SlidePart>("OutPutSlideResult-" + SlideRef);

            SlideRef++;
            //Add the slide template content into the new slide.

            newSlidePart.FeedData(inputSlide.GetStream(FileMode.Open));
            //Make sure the new slide references the proper slide layout.
            newSlidePart.AddPart(inputSlide.SlideLayoutPart);
            //Get the list of slide ids.
            SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;
            //Deternmine where to add the next slide (find max number of slides).
            uint    maxSlideId  = 1;
            SlideId prevSlideId = null;

            foreach (SlideId slideID in slideIdList.ChildElements)
            {
                if (slideID.Id > maxSlideId)
                {
                    maxSlideId  = slideID.Id;
                    prevSlideId = slideID;
                }
            }
            maxSlideId++;
            //Add the new slide at the end of the deck.
            SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);

            //Make sure the id and relid are set appropriately.
            newSlideId.Id             = maxSlideId;
            newSlideId.RelationshipId = presentationPart.GetIdOfPart(newSlidePart);
            return(newSlidePart);
        }
        private SlidePart CloneSlidePart(SlidePart ticketSlide)
        {
            Slide     currSlide = (Slide)ticketSlide.Slide.CloneNode(true);
            SlidePart sp        = document.PresentationPart.AddNewPart <SlidePart>();

            currSlide.Save(sp);
            using (var stream = ticketSlide.GetStream())
            {
                sp.FeedData(stream);
                sp.AddPart(ticketSlide.SlideLayoutPart);
            }

            return(sp);
        }
Example #9
0
        public bool CloneSlidePart(int i)
        {
            using (PresentationDocument ppt = PresentationDocument.Open(HttpContext.Current.Server.MapPath(folder), true))
            {
                PresentationPart   presentationPart = ppt.PresentationPart;
                OpenXmlElementList slideIds         = presentationPart.Presentation.SlideIdList.ChildElements;
                string             relId            = (slideIds[0] as SlideId).RelationshipId;

                //
                uint max = (slideIds[0] as SlideId).Id;
                uint k   = 0;
                for (int j = 0; j < i; j++)
                {
                    k = (slideIds[j] as SlideId).Id;
                    if (k > max)
                    {
                        max = k;
                    }
                }

                SlidePart slideTemplate = (SlidePart)presentationPart.GetPartById(relId);
                SlidePart newSlidePart  = presentationPart.AddNewPart <SlidePart>("newSlide" + max);
                newSlidePart.FeedData(slideTemplate.GetStream(FileMode.Open));
                newSlidePart.AddPart(slideTemplate.SlideLayoutPart);
                SlideIdList slideIdList = presentationPart.Presentation.SlideIdList;
                uint        maxSlideId  = 1;
                SlideId     prevSlideId = null;
                foreach (SlideId slideId in slideIdList.ChildElements)
                {
                    if (slideId.Id > maxSlideId)
                    {
                        maxSlideId  = slideId.Id;
                        prevSlideId = slideId;
                    }
                }
                maxSlideId++;
                SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);
                newSlideId.Id             = maxSlideId;
                newSlideId.RelationshipId = presentationPart.GetIdOfPart(newSlidePart);

                if (newSlidePart != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Example #10
0
        public void InsertNewSlide(PresentationDocument presentationDocument)
        {
            var       presentationPart = presentationDocument.PresentationPart;
            SlidePart slidePart1       = presentationPart.AddNewPart <SlidePart>();

            Slide slide1 = new Slide();

            slide1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
            slide1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            slide1.AddNamespaceDeclaration("p", "http://schemas.openxmlformats.org/presentationml/2006/main");

            var shapeTree = InitCommonProperty(slide1);

            uint objectID            = 4;
            var  slidePartChildIndex = SlideWriterHelper.CreateHyperLinkMap(SlideContent, slidePart1, HyperLinkIDMap);

            ImageWriter.CreateImageMap(SlideContent, slidePart1, slidePartChildIndex);

            foreach (var bodyContent in SlideContent.TextAreas)
            {
                if (bodyContent.Texts.Count > 0)
                {
                    AddTextBox(shapeTree, objectID++, bodyContent);
                }
            }

            objectID = ImageWriter.AddImageContents(shapeTree, objectID);

            foreach (var tableContent in SlideContent.Tables)
            {
                AddTableContent(shapeTree, objectID++, tableContent);
            }


            slide1.Save(slidePart1);

            // スライドレイアウトの設定
            var slideMaster = presentationPart.SlideMasterParts.First();
            var slideLayout = slideMaster.GetPartById(SlideLayouts.SlideLayouts[SlideContent.SlideLayout].ID);

            slidePart1.AddPart(slideLayout);

            SlideWriterHelper.SetSlideID(presentationPart, slidePart1);

            // Save the modified presentation.
            presentationPart.Presentation.Save();
        }
        /// <summary>
        /// Insert a new Slide into PowerPoint
        /// </summary>
        /// <param name="presentationPart">Presentation Part</param>
        /// <param name="layoutName">Layout of the new Slide</param>
        /// <returns>Slide Instance</returns>
        public Slide InsertSlide(PresentationPart presentationPart, string layoutName)
        {
            UInt32 slideId = 256U;

            // Get the Slide Id collection of the presentation document
            var slideIdList = presentationPart.Presentation.SlideIdList;

            if (slideIdList == null)
            {
                throw new NullReferenceException("The number of slide is empty, please select a ppt with a slide at least again");
            }

            slideId += Convert.ToUInt32(slideIdList.Count());

            // Creates a Slide instance and adds its children.
            Slide slide = new Slide(new CommonSlideData(new ShapeTree()));

            SlidePart slidePart = presentationPart.AddNewPart <SlidePart>();

            slide.Save(slidePart);

            // Get SlideMasterPart and SlideLayoutPart from the existing Presentation Part
            SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.First();
            SlideLayoutPart slideLayoutPart = slideMasterPart.SlideLayoutParts.SingleOrDefault
                                                  (sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName, StringComparison.OrdinalIgnoreCase));

            if (slideLayoutPart == null)
            {
                throw new Exception("The slide layout " + layoutName + " is not found");
            }

            slidePart.AddPart <SlideLayoutPart>(slideLayoutPart);

            slidePart.Slide.CommonSlideData = (CommonSlideData)slideMasterPart.SlideLayoutParts.SingleOrDefault(
                sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName)).SlideLayout.CommonSlideData.Clone();

            // Create SlideId instance and Set property
            SlideId newSlideId = presentationPart.Presentation.SlideIdList.AppendChild <SlideId>(new SlideId());

            newSlideId.Id             = slideId;
            newSlideId.RelationshipId = presentationPart.GetIdOfPart(slidePart);

            return(GetSlideByRelationShipId(presentationPart, newSlideId.RelationshipId));
        }
Example #12
0
        internal static Slide InsertSlide(this PresentationPart presentationPart, string layoutName)
        {
            //1) create the slide
            Slide slide = new Slide(new CommonSlideData(new ShapeTree()));

            ////2) specify 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();

            ////3) Specify the group shape properties of the new slide.
            //slide.CommonSlideData.ShapeTree.AppendChild(new GroupShapeProperties());

            //4) create slide part for the new slide inside the presentation part
            SlidePart sPart = presentationPart.AddNewPart <SlidePart>();

            slide.Save(sPart);

            //5) set the slidelayout
            SlideMasterPart smPart = presentationPart.SlideMasterParts.First();
            SlideLayoutPart slPart = smPart.SlideLayoutParts.SingleOrDefault(sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName));

            sPart.AddPart <SlideLayoutPart>(slPart);

            //sPart.CommonSlideData = (CommonSlideData)smPart.SlideLayoutParts.SingleOrDefault(
            //    sl => sl.SlideLayout.CommonSlideData.Name.Value.Equals(layoutName)).SlideLayout.CommonSlideData.Clone();

            //6) set the slideid
            UInt32 slideId = 256U;

            slideId += Convert.ToUInt32(presentationPart.Presentation.SlideIdList.Count());
            SlideId newSlideId = presentationPart.Presentation.SlideIdList.AppendChild <SlideId>(new SlideId());

            newSlideId.Id             = slideId;
            newSlideId.RelationshipId = presentationPart.GetIdOfPart(sPart);

            return(GetSlideByRelationshipId(presentationPart, newSlideId.RelationshipId));
        }
        public static void AddNote(string docName, int index)
        {
            try
            {
                string relId = "rId" + (index + 1);
                using (PresentationDocument ppt = PresentationDocument.Open(docName, false))
                {
                    PresentationPart   part     = ppt.PresentationPart;
                    OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;

                    relId = (slideIds[index] as SlideId).RelationshipId;
                }
                using (PresentationDocument ppt = PresentationDocument.Open(docName, true))
                {
                    PresentationPart presentationPart1 = ppt.PresentationPart;
                    SlidePart        slidePart2        = (SlidePart)presentationPart1.GetPartById(relId);
                    NotesSlidePart   notesSlidePart1;
                    string           existingSlideNote = "";

                    if (slidePart2.NotesSlidePart != null)
                    {
                        //Appened new note to existing note.
                        existingSlideNote = slidePart2.NotesSlidePart.NotesSlide.InnerText + "\n";
                        var val = (NotesSlidePart)slidePart2.GetPartById(relId);
                        notesSlidePart1 = slidePart2.AddPart <NotesSlidePart>(val, relId);
                    }
                    else
                    {
                        //Add a new noteto a slide.
                        notesSlidePart1 = slidePart2.AddNewPart <NotesSlidePart>(relId);
                    }

                    NotesSlide notesSlide = new NotesSlide(
                        new CommonSlideData(new ShapeTree(
                                                new P.NonVisualGroupShapeProperties(
                                                    new P.NonVisualDrawingProperties()
                    {
                        Id = (UInt32Value)1U, Name = ""
                    },
                                                    new P.NonVisualGroupShapeDrawingProperties(),
                                                    new ApplicationNonVisualDrawingProperties()),
                                                new GroupShapeProperties(new A.TransformGroup()),
                                                new P.Shape(
                                                    new P.NonVisualShapeProperties(
                                                        new P.NonVisualDrawingProperties()
                    {
                        Id = (UInt32Value)2U, Name = "Slide Image Placeholder 1"
                    },
                                                        new P.NonVisualShapeDrawingProperties(new A.ShapeLocks()
                    {
                        NoGrouping = true, NoRotation = true, NoChangeAspect = true
                    }),
                                                        new ApplicationNonVisualDrawingProperties(new PlaceholderShape()
                    {
                        Type = PlaceholderValues.SlideImage
                    })),
                                                    new P.ShapeProperties()),
                                                new P.Shape(
                                                    new P.NonVisualShapeProperties(
                                                        new P.NonVisualDrawingProperties()
                    {
                        Id = (UInt32Value)3U, Name = "Notes Placeholder 2"
                    },
                                                        new P.NonVisualShapeDrawingProperties(new A.ShapeLocks()
                    {
                        NoGrouping = true
                    }),
                                                        new ApplicationNonVisualDrawingProperties(new PlaceholderShape()
                    {
                        Type = PlaceholderValues.Body, Index = (UInt32Value)1U
                    })),
                                                    new P.ShapeProperties(),
                                                    new P.TextBody(
                                                        new A.BodyProperties(),
                                                        new A.ListStyle(),
                                                        new A.Paragraph(
                                                            new A.Run(
                                                                new A.RunProperties()
                    {
                        Language = "en-US", Dirty = false
                    },
                                                                new A.Text()
                    {
                        Text = existingSlideNote + "Value Updated"
                    }),
                                                            new A.EndParagraphRunProperties()
                    {
                        Language = "en-US", Dirty = false
                    }))
                                                    ))),
                        new ColorMapOverride(new A.MasterColorMapping()));

                    notesSlidePart1.NotesSlide = notesSlide;
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
                Console.ReadLine();
            }
        }
        public static Slide 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 GroupShapeProperties());
            // 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);
            string str = new StreamReader(slidePart.GetStream()).ReadToEnd();

            return(slidePart.Slide);

            // Save the modified presentation.
            //presentationPart.Presentation.Save();
        }
        // Insert the specified slide into the presentation at the specified position.
        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 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 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 presentation.
            presentationPart.Presentation.Save();
        }
Example #16
0
        // Insert the specified slide into the presentation at the specified position.
        public void InsertNewSlide(PresentationPart 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 P.ShapeTree()));

            // Specify the group shape properties of the new slide.
            slide.CommonSlideData.ShapeTree.AppendChild(new P.GroupShapeProperties());

            // 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  = Convert.ToUInt32(slideIdList.ChildElements.Count());
            int     position    = slideIdList.ChildElements.Count();
            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 presentation.
            presentationPart.Presentation.Save();
        }
Example #17
0
        // Insert the specified slide into the presentation at the specified position.
        public static Slide InsertNewSlide(PresentationDocument presentationDocument, int position, string slideTitle, FileInfo ChartFile)
        {
            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 GroupShapeProperties());

            //// Declare and instantiate the title shape of the new slide.
            //DocumentFormat.OpenXml.Presentation.Shape titleShape = slide.CommonSlideData.ShapeTree.AppendChild(new DocumentFormat.OpenXml.Presentation.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 DocumentFormat.OpenXml.Presentation.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.
            //DocumentFormat.OpenXml.Presentation.Shape bodyShape = slide.CommonSlideData.ShapeTree.AppendChild(new DocumentFormat.OpenXml.Presentation.Shape());
            //drawingObjectId++;

            //// Specify the required shape properties for the body shape.
            //bodyShape.NonVisualShapeProperties = new NonVisualShapeProperties(new NonVisualDrawingProperties() { Id = drawingObjectId, Name = "Content Placeholder" },
            //        new NonVisualShapeDrawingProperties(new Drawing.ShapeLocks() { NoGrouping = true }),
            //        new ApplicationNonVisualDrawingProperties(new PlaceholderShape() { Index = 1 }));
            //bodyShape.ShapeProperties = new DocumentFormat.OpenXml.Presentation.ShapeProperties();

            //// Specify the text of the body shape.
            //bodyShape.TextBody = new TextBody(new Drawing.BodyProperties(),
            //        new Drawing.ListStyle(),
            //        new Drawing.Paragraph());

            // Declare and instantiate the body shape of the new slide.
            //DocumentFormat.OpenXml.Presentation.Shape ImgShape = slide.CommonSlideData.ShapeTree.AppendChild(new DocumentFormat.OpenXml.Presentation.Shape());
            //drawingObjectId++;

            // Specify the required shape properties for the body shape.
            //ImgShape.NonVisualShapeProperties = new NonVisualShapeProperties(new NonVisualDrawingProperties() { Id = drawingObjectId, Name = "" },
            //        new NonVisualGroupShapeDrawingProperties(),
            //        new ApplicationNonVisualDrawingProperties());
            //ImgShape.ShapeProperties = new DocumentFormat.OpenXml.Presentation.ShapeProperties();

            // Specify the text of the body shape.
            //ImgShape.TextBody = new TextBody(new Drawing.BodyProperties(),
            //        new Drawing.ListStyle(),
            //        new Drawing.Paragraph());

            //Drawing.Picture picture = new Drawing.Picture();
            ////string embedId = string.Empty;
            //string embedId = "rId" + (slide.Elements().Count() + 915).ToString();
            //Drawing.NonVisualPictureProperties nonVisualPictureProperties = new Drawing.NonVisualPictureProperties(
            //    new Drawing.NonVisualDrawingProperties() { Id = (UInt32Value)4U, Name = "Picture" + ChartFile.Name },
            //    new Drawing.NonVisualPictureDrawingProperties(new Drawing.PictureLocks() { NoChangeAspect = true }),
            //    new ApplicationNonVisualDrawingProperties());


            //BlipFill blipFill1 = new BlipFill();
            //Drawing.Blip blip1 = new Drawing.Blip() { Embed = embedId, CompressionState = Drawing.BlipCompressionValues.Print };

            //// Creates an BlipExtensionList instance and adds its children
            //Drawing.BlipExtensionList blipExtensionList = new Drawing.BlipExtensionList();
            //Drawing.BlipExtension blipExtension = new Drawing.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };

            //A14.UseLocalDpi useLocalDpi = new A14.UseLocalDpi() { Val = false };
            //useLocalDpi.AddNamespaceDeclaration("a14",
            //    "http://schemas.microsoft.com/office/drawing/2010/main");

            //blipExtension.Append(useLocalDpi);
            //blipExtensionList.Append(blipExtension);
            //blip1.Append(blipExtensionList);


            //Drawing.Stretch stretch1 = new Drawing.Stretch();
            //Drawing.FillRectangle fillRectangle1 = new Drawing.FillRectangle();
            //stretch1.Append(fillRectangle1);

            //blipFill1.Append(blip1);
            //blipFill1.Append(stretch1);

            //Drawing.ShapeProperties shapeProperties = new Drawing.ShapeProperties();

            //Drawing.Transform2D transform2D = new Drawing.Transform2D();
            //Drawing.Offset offset = new Drawing.Offset() { X = 0L, Y = 0L };
            //Drawing.Extents extents = new Drawing.Extents() { Cx = 8000000L, Cy = 6000000L };

            //transform2D.Append(offset);
            //transform2D.Append(extents);


            //Drawing.PresetGeometry presetGeometry = new Drawing.PresetGeometry() { Preset = Drawing.ShapeTypeValues.Rectangle };
            //Drawing.AdjustValueList adjustValueList = new Drawing.AdjustValueList();


            //presetGeometry.Append(adjustValueList);


            //shapeProperties.Append(transform2D);
            //shapeProperties.Append(presetGeometry);


            //picture.Append(nonVisualPictureProperties);
            //picture.Append(blipFill1);
            //picture.Append(shapeProperties);


            //slide.CommonSlideData.ShapeTree.AppendChild(picture);



            // 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 presentation.
            //presentationPart.Presentation.Save();

            return(GetSlideByRelationShipId(presentationPart, newSlideId.RelationshipId));
        }
Example #18
0
        public SlidePart AddNewSlide()
        {
            Slide slide = new Slide(
                new CommonSlideData(new ShapeTree()),
                new ColorMapOverride(new D.MasterColorMapping())
                );
            NonVisualGroupShapeProperties nonVisualProperties =
                slide.CommonSlideData.ShapeTree.AppendChild(new NonVisualGroupShapeProperties());

            nonVisualProperties.NonVisualDrawingProperties = new NonVisualDrawingProperties()
            {
                Id = 1, Name = ""
            };
            nonVisualProperties.NonVisualGroupShapeDrawingProperties  = new NonVisualGroupShapeDrawingProperties();
            nonVisualProperties.ApplicationNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties();
            slide.CommonSlideData.ShapeTree.AppendChild(
                new GroupShapeProperties()
            {
                TransformGroup = new D.TransformGroup
                                 (
                    new D.Offset()
                {
                    X = 0L, Y = 0L
                },
                    new D.Extents()
                {
                    Cx = 0L, Cy = 0L
                },
                    new D.ChildOffset()
                {
                    X = 0L, Y = 0L
                },
                    new D.ChildExtents()
                {
                    Cx = 0L, Cy = 0L
                }
                                 )
            });
            CommonSlideDataExtensionList commonSlideDataExtensionList1 = new CommonSlideDataExtensionList();
            CommonSlideDataExtension     commonSlideDataExtension1     = new CommonSlideDataExtension()
            {
                Uri = "{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}"
            };

            P14.CreationId creationId1 = new P14.CreationId()
            {
                Val = (UInt32Value)4033567156U
            };
            creationId1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main");
            commonSlideDataExtension1.Append(creationId1);
            commonSlideDataExtensionList1.Append(commonSlideDataExtension1);
            slide.CommonSlideData.Append(commonSlideDataExtensionList1);
            SlidePart slidePart   = Doc.PresentationPart.AddNewPart <SlidePart>();
            var       slideIdList = Doc.PresentationPart.Presentation.SlideIdList;

            slide.Save(slidePart);
            uint    maxSlideId  = 1;
            SlideId prevSlideId = null;

            foreach (SlideId slideId in slideIdList.ChildElements)
            {
                if (slideId.Id > maxSlideId)
                {
                    maxSlideId  = slideId.Id;
                    prevSlideId = slideId;
                }
            }
            maxSlideId++;
            SlidePart lastSlidePart;

            if (prevSlideId != null)
            {
                lastSlidePart = (SlidePart)Doc.PresentationPart.GetPartById(prevSlideId.RelationshipId);
            }
            else
            {
                lastSlidePart = (SlidePart)Doc.PresentationPart
                                .GetPartById(((SlideId)(slideIdList.ChildElements[0])).RelationshipId);
            }
            if (null != lastSlidePart.SlideLayoutPart)
            {
                slidePart.AddPart(lastSlidePart.SlideLayoutPart);
            }
            SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId);

            newSlideId.Id             = maxSlideId;
            newSlideId.RelationshipId = Doc.PresentationPart.GetIdOfPart(slidePart);
            Doc.PresentationPart.Presentation.Save();
            return(slidePart);
        }