예제 #1
0
        /// <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));
        }
        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));
 }
예제 #4
0
        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);
        }
예제 #6
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);
                }
            }
        }