示例#1
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));
        }
示例#2
0
        static SlidePart CreateSlidePart(PresentationPart presentationPart)
        {
            var slidePart1 = presentationPart.AddNewPart <SlidePart>("rId2");

            slidePart1.Slide = new Slide(
                new CommonSlideData(new ShapeTree(
                                        new P.NonVisualGroupShapeProperties(
                                            new P.NonVisualDrawingProperties {
                Id = 1U, Name = ""
            },
                                            new P.NonVisualGroupShapeDrawingProperties(),
                                            new ApplicationNonVisualDrawingProperties()),
                                        new GroupShapeProperties(new TransformGroup()),
                                        new P.Shape(
                                            new P.NonVisualShapeProperties(
                                                new P.NonVisualDrawingProperties {
                Id = 2U, Name = "Title 1"
            },
                                                new P.NonVisualShapeDrawingProperties(new ShapeLocks {
                NoGrouping = true
            }),
                                                new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
                                            new P.ShapeProperties(),
                                            new P.TextBody(
                                                new BodyProperties(),
                                                new ListStyle(),
                                                new Paragraph(new EndParagraphRunProperties {
                Language = "en-US"
            }))))),
                new ColorMapOverride(new MasterColorMapping()));
            return(slidePart1);
        }
        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);
        }
示例#4
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 static SlidePart CreateSlidePart(PresentationPart presentationPart)
        {
            SlidePart slidePart = presentationPart.AddNewPart <SlidePart>(slidePartRId);

            slidePart.Slide = CreateSlide();
            return(slidePart);
        }
示例#6
0
        // Adds child parts and generates content of the specified part.
        public void _CreatePresentationPart(PresentationPart part)
        {
            PresentationPropertiesPart presentationPropertiesPart1 = part.AddNewPart <PresentationPropertiesPart>("rId3");

            GeneratePresentationPropertiesPart1Content(presentationPropertiesPart1);

            TableStylesPart tableStylesPart1 = part.AddNewPart <TableStylesPart>("rId6");

            GenerateTableStylesPart1Content(tableStylesPart1);

            ViewPropertiesPart viewPropertiesPart1 = part.AddNewPart <ViewPropertiesPart>("rId4");

            GenerateViewPropertiesPart1Content(viewPropertiesPart1);

            GeneratePartContent_4x3(part);
        }
示例#7
0
        public static SlidePart CreateSlidePart(PresentationPart presentationPart, string SlideID, PPTXSetting FileSettings)
        {
            SlidePart slidePart1 = presentationPart.AddNewPart <SlidePart>(SlideID);

            GenerateSlidePart1Content(slidePart1, FileSettings.Title, FileSettings.SubTitle);

            return(slidePart1);
        }
        public void CreateSlides(List <string> imageFileNames,
                                 string newPresentation)
        {
            string  relId;
            SlideId slideId;

            uint currentSlideId = 256;

            string imageFileNameNoPath;

            long imageWidthEMU  = 0;
            long imageHeightEMU = 0;

            // Open the new presentation.
            using (PresentationDocument newDeck =
                       PresentationDocument.Open(newPresentation, true))
            {
                PresentationPart presentationPart = newDeck.PresentationPart;
                var slideMasterPart = presentationPart.SlideMasterParts.First();
                var slideLayoutPart = slideMasterPart.SlideLayoutParts.First();
                if (presentationPart.Presentation.SlideIdList == null)
                {
                    presentationPart.Presentation.SlideIdList = new SlideIdList();
                }
                foreach (string imageFileNameWithPath in imageFileNames)
                {
                    imageFileNameNoPath =
                        Path.GetFileNameWithoutExtension(imageFileNameWithPath);
                    relId = "rel" + currentSlideId;

                    ImagePartType imagePartType = ImagePartType.Png;
                    byte[]        imageBytes    = GetImageData(imageFileNameWithPath, ref imagePartType, ref imageWidthEMU, ref imageHeightEMU);
                    var           slidePart     = presentationPart.AddNewPart <SlidePart>(relId);
                    GenerateSlidePart(imageFileNameNoPath, imageFileNameNoPath, imageWidthEMU, imageHeightEMU).Save(slidePart);

                    // Add the relationship between the slide and the
                    // slide layout.
                    slidePart.AddPart <SlideLayoutPart>(slideLayoutPart);
                    var imagePart = slidePart.AddImagePart(ImagePartType.Jpeg, "relId12");
                    GenerateImagePart(imagePart, imageBytes);

                    // Add the new slide to the slide list.
                    slideId = new SlideId();
                    slideId.RelationshipId = relId;
                    slideId.Id             = currentSlideId;
                    presentationPart.Presentation.SlideIdList.Append(slideId);

                    // Increment the slide id;
                    currentSlideId++;
                }

                // Save the changes to the slide master part.
                slideMasterPart.SlideMaster.Save();

                // Save the changes to the new deck.
                presentationPart.Presentation.Save();
            }
        }
        private static List <SlidePart> CreateImageSlideParts(PresentationPart presentationPart, List <SvgDocument> svgDocs)
        {
            int           id = 256;
            string        relId;
            SlideId       newSlideId;
            SlideLayoutId newSlideLayoutId;
            uint          uniqueId   = GetMaxUniqueId(presentationPart);
            uint          maxSlideId = GetMaxSlideId(presentationPart.Presentation.SlideIdList);
            // get first slide master part: template
            SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.First();

            List <SlidePart> slideParts = new List <SlidePart>();

            for (int i = 0; i < svgDocs.Count; i++)
            {
                id++;
                using (MemoryStream ms = new MemoryStream())
                {
                    using (System.Drawing.Bitmap image = svgDocs[i].Draw())
                    {
                        image.Save(ms, ImageFormat.Bmp);
                        ms.Seek(0, SeekOrigin.Begin);
                        relId = "rId" + id;
                        // add new slide part
                        SlidePart slidePart = presentationPart.AddNewPart <SlidePart>(relId);

                        // add image part to slide part
                        ImagePart imagePart = slidePart.AddImagePart(ImagePartType.Bmp, relId);
                        imagePart.FeedData(ms);
                        // add image slide
                        CreateImageSlide(relId).Save(slidePart);

                        // add slide layout part to slide part
                        SlideLayoutPart slideLayoutPart = slidePart.AddNewPart <SlideLayoutPart>();
                        CreateSlideLayoutPart().Save(slideLayoutPart);
                        slideMasterPart.AddPart(slideLayoutPart);
                        slideLayoutPart.AddPart(slideMasterPart);

                        uniqueId++;
                        newSlideLayoutId = new SlideLayoutId();
                        newSlideLayoutId.RelationshipId = slideMasterPart.GetIdOfPart(slideLayoutPart);
                        newSlideLayoutId.Id             = uniqueId;
                        slideMasterPart.SlideMaster.SlideLayoutIdList.Append(newSlideLayoutId);

                        // add slide part to presentaion slide list
                        maxSlideId++;
                        newSlideId = new SlideId();
                        newSlideId.RelationshipId = relId;
                        newSlideId.Id             = maxSlideId;
                        presentationPart.Presentation.SlideIdList.Append(newSlideId);
                    }
                }
            }
            slideMasterPart.SlideMaster.Save();
            return(slideParts);
        }
示例#10
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);
        }
示例#11
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);
        }
示例#12
0
        /// <summary>
        /// replace the current theme with a user specified theme
        /// </summary>
        /// <param name="document">document file lcoation</param>
        /// <param name="themeFile">theme xml file location</param>
        /// <param name="app">which app is the document</param>
        public static void ReplaceTheme(string document, string themeFile, string app)
        {
            if (app == "Word")
            {
                using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
                {
                    MainDocumentPart mainPart = wordDoc.MainDocumentPart;

                    // Delete the old document part.
                    mainPart.DeletePart(mainPart.ThemePart);

                    // Add a new document part and then add content.
                    ThemePart themePart = mainPart.AddNewPart <ThemePart>();

                    using (StreamReader streamReader = new StreamReader(themeFile))
                        using (StreamWriter streamWriter = new StreamWriter(themePart.GetStream(FileMode.Create)))
                        {
                            streamWriter.Write(streamReader.ReadToEnd());
                        }
                }
            }
            else if (app == "PowerPoint")
            {
                using (PresentationDocument presDoc = PresentationDocument.Open(document, true))
                {
                    PresentationPart mainPart = presDoc.PresentationPart;
                    mainPart.DeletePart(mainPart.ThemePart);
                    ThemePart themePart = mainPart.AddNewPart <ThemePart>();

                    using (StreamReader streamReader = new StreamReader(themeFile))
                        using (StreamWriter streamWriter = new StreamWriter(themePart.GetStream(FileMode.Create)))
                        {
                            streamWriter.Write(streamReader.ReadToEnd());
                        }
                }
            }
            else
            {
                using (SpreadsheetDocument excelDoc = SpreadsheetDocument.Open(document, true))
                {
                    WorkbookPart mainPart = excelDoc.WorkbookPart;
                    mainPart.DeletePart(mainPart.ThemePart);
                    ThemePart themePart = mainPart.AddNewPart <ThemePart>();

                    using (StreamReader streamReader = new StreamReader(themeFile))
                        using (StreamWriter streamWriter = new StreamWriter(themePart.GetStream(FileMode.Create)))
                        {
                            streamWriter.Write(streamReader.ReadToEnd());
                        }
                }
            }
        }
示例#13
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);
                }
            }
        }
示例#14
0
        internal static void ApplyTheme(PresentationPart presentationPart, Drawing.Theme theme)
        {
            string themeId = null;

            if (presentationPart.ThemePart != null)
            {
                themeId = presentationPart.GetIdOfPart(presentationPart.ThemePart);
                presentationPart.DeletePart(themeId);
            }
            else
            {
                themeId = presentationPart.GetNextRelationshipId();
            }

            ThemePart themePart = presentationPart.AddNewPart <ThemePart>(themeId);

            theme.Save(themePart);
        }
示例#15
0
        internal static void ApplyTableStyles(PresentationPart presentationPart, Drawing.TableStyleList tableStyleList)
        {
            string tableStylesId = null;

            if (presentationPart.TableStylesPart != null)
            {
                tableStylesId = presentationPart.GetIdOfPart(presentationPart.TableStylesPart);
                presentationPart.DeletePart(tableStylesId);
            }
            else
            {
                tableStylesId = presentationPart.GetNextRelationshipId();
            }

            TableStylesPart tableStylesPart = presentationPart.AddNewPart <TableStylesPart>(tableStylesId);

            tableStyleList.Save(tableStylesPart);
        }
        /// <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));
        }
示例#17
0
        private static SlidePart CreateSlidePart(PresentationPart presentationPart, string slideIdx, uint uid)
        {
            SlidePart slidePart = presentationPart.AddNewPart <SlidePart>(slideIdx);

            slidePart.Slide = new Slide(new CommonSlideData(
                                            new P.NonVisualGroupShapeProperties(
                                                new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)1U, Name = ""
            },
                                                new P.NonVisualGroupShapeDrawingProperties(),
                                                new ApplicationNonVisualDrawingProperties()),
                                            new GroupShapeProperties(new TransformGroup())));
            presentationPart.Presentation.SlideIdList.Append(new SlideId()
            {
                Id = uid--, RelationshipId = slideIdx
            });
            return(slidePart);
        }
示例#18
0
        private static SlidePart CreateAddSlidePart(PresentationPart presentationPart, string addid)
        {
            SlidePart slidePart1 = presentationPart.AddNewPart <SlidePart>(addid);

            slidePart1.Slide = new Slide(
                new CommonSlideData(
                    new ShapeTree(
                        new P.NonVisualGroupShapeProperties(
                            new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)1U, Name = ""
            },
                            new P.NonVisualGroupShapeDrawingProperties(),
                            new ApplicationNonVisualDrawingProperties()),
                        new GroupShapeProperties(new D.TransformGroup())
                        )),
                new ColorMapOverride(new D.MasterColorMapping()));
            //缺少引用建立slideidlist
            return(slidePart1);
        }
示例#19
0
        private static SlidePart CreateSlidePart(PresentationPart presentationPart)
        {
            SlidePart slidePart1 = presentationPart.AddNewPart <SlidePart>("rId2");

            slidePart1.Slide = new Slide(
                new CommonSlideData(
                    new ShapeTree(
                        new P.NonVisualGroupShapeProperties(
                            new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)1U, Name = ""
            },
                            new P.NonVisualGroupShapeDrawingProperties(),
                            new ApplicationNonVisualDrawingProperties()),
                        new GroupShapeProperties(new TransformGroup()),
                        new P.Shape(
                            new P.NonVisualShapeProperties(
                                new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)2U, Name = "Title 1"
            },
                                new P.NonVisualShapeDrawingProperties(new ShapeLocks()
            {
                NoGrouping = true
            }),
                                new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
                            new P.ShapeProperties(),
                            new P.TextBody(
                                new BodyProperties(),
                                new ListStyle(),
                                new Paragraph(new D.Run(new D.Text()
            {
                Text = "\t\tThis presentation has been created by Kashish Jhaveri"
            }), new EndParagraphRunProperties()
            {
                Language = "en-US"
            }))))),
                new ColorMapOverride(new MasterColorMapping()));
            return(slidePart1);
        }
示例#20
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));
        }
示例#21
0
        private static SlidePart CreateSlidePart(PresentationPart presentationPart)
        {
            SlidePart slidePart1 = presentationPart.AddNewPart <SlidePart>("rId2");

            slidePart1.Slide = new P.Slide(
                new P.CommonSlideData(
                    new P.ShapeTree(
                        new P.NonVisualGroupShapeProperties(
                            new P.NonVisualDrawingProperties()
            {
                Id = 1U, Name = string.Empty
            },
                            new P.NonVisualGroupShapeDrawingProperties(),
                            new P.ApplicationNonVisualDrawingProperties()),
                        new P.GroupShapeProperties(new D.TransformGroup()),
                        new P.Shape(
                            new P.NonVisualShapeProperties(
                                new P.NonVisualDrawingProperties()
            {
                Id = 2U, Name = "Title 1"
            },
                                new P.NonVisualShapeDrawingProperties(new D.ShapeLocks()
            {
                NoGrouping = true
            }),
                                new P.ApplicationNonVisualDrawingProperties(new P.PlaceholderShape())),
                            new P.ShapeProperties(),
                            new P.TextBody(
                                new D.BodyProperties(),
                                new D.ListStyle(),
                                new D.Paragraph(new D.EndParagraphRunProperties()
            {
                Language = "en-US"
            }))))),
                new P.ColorMapOverride(new D.MasterColorMapping()));
            return(slidePart1);
        }
        private static SlidePart CreateSlidePart(PresentationPart presentationPart)
        {
            SlidePart slidePart1 = presentationPart.AddNewPart <SlidePart>("rId2");

            slidePart1.Slide = new Slide(
                new CommonSlideData(
                    new ShapeTree(
                        new P.NonVisualGroupShapeProperties(
                            new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)1U, Name = ""
            },
                            new P.NonVisualGroupShapeDrawingProperties(),
                            new ApplicationNonVisualDrawingProperties()),
                        new GroupShapeProperties(new TransformGroup()),
                        new P.Shape(
                            new P.NonVisualShapeProperties(
                                new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)2U, Name = ""
            },
                                new P.NonVisualShapeDrawingProperties(new ShapeLocks()
            {
                NoGrouping = true
            }),
                                new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
                            new P.ShapeProperties(),
                            new P.TextBody(
                                new BodyProperties(),
                                new ListStyle(),
                                new Paragraph(new D.Run(new D.Text()
            {
                Text = "Hello, my name is Sumit"
            })))))),
                new ColorMapOverride(new MasterColorMapping()));
            return(slidePart1);
        }
示例#23
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));
        }
        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();
        }
示例#26
0
        private static SlidePart CreateSlidePart(PresentationPart presentationPart)
        {
            SlidePart  slidePart1 = presentationPart.AddNewPart <SlidePart>("rId2");
            ImagePart  image      = slidePart1.AddImagePart(ImagePartType.Png, "relId12");
            FileStream fs         = new FileStream("d:\\2.jpg", FileMode.Open);

            image.FeedData(fs);
            fs.Close();

            slidePart1.Slide =
                new Slide(
                    new CommonSlideData(
                        new ShapeTree(
                            new P.NonVisualGroupShapeProperties(
                                new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)1U, Name = ""
            },
                                new P.NonVisualGroupShapeDrawingProperties(),
                                new ApplicationNonVisualDrawingProperties()),
                            new GroupShapeProperties(
                                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
            })),
                            new P.Picture(
                                new P.NonVisualPictureProperties(
                                    new P.NonVisualDrawingProperties()
            {
                Id          = (UInt32Value)4U,
                Name        = "aa",
                Description = "aa"
            },
                                    new P.NonVisualPictureDrawingProperties(
                                        new D.PictureLocks()
            {
                NoChangeAspect = true
            }),
                                    new ApplicationNonVisualDrawingProperties()),
                                new P.BlipFill(
                                    new D.Blip()
            {
                Embed = "relId12"
            },
                                    new D.Stretch(
                                        new D.FillRectangle())),
                                new P.ShapeProperties(
                                    new D.Transform2D(
                                        new D.Offset()
            {
                X = 0L, Y = 0L
            },
                                        new D.Extents()
            {
                Cx = 9144000,
                Cy = 6858000
            }),
                                    new D.PresetGeometry(
                                        new D.AdjustValueList())
            {
                Preset = D.ShapeTypeValues.Rectangle
            }
                                    )))),
                    new ColorMapOverride(
                        new D.MasterColorMapping()));
            return(slidePart1);
        }
示例#27
0
    void CreateSlides(List <string> imageFileNames, string newPresentation)
    {
        string  relId;
        SlideId slideId;

        // Slide identifiers have a minimum value of greater than or equal to 256
        // and a maximum value of less than 2147483648. Assume that the template
        // presentation being used has no slides.
        uint currentSlideId = 256;

        string imageFileNameNoPath;

        long imageWidthEMU  = 0;
        long imageHeightEMU = 0;

        // Open the new presentation.
        using (PresentationDocument newDeck = PresentationDocument.Open(newPresentation, true))
        {
            PresentationPart presentationPart = newDeck.PresentationPart;

            // Reuse the slide master part. This code assumes that the template presentation
            // being used has at least one master slide.
            var slideMasterPart = presentationPart.SlideMasterParts.First();

            // Reuse the slide layout part. This code assumes that the template presentation
            // being used has at least one slide layout.
            var slideLayoutPart = slideMasterPart.SlideLayoutParts.First();

            // If the new presentation doesn't have a SlideIdList element yet then add it.
            if (presentationPart.Presentation.SlideIdList == null)
            {
                presentationPart.Presentation.SlideIdList = new SlideIdList();
            }

            // Loop through each image file creating slides in the new presentation.
            foreach (string imageFileNameWithPath in imageFileNames)
            {
                if (Step != null)
                {
                    Step();
                }

                imageFileNameNoPath = Path.GetFileNameWithoutExtension(imageFileNameWithPath);

                // Create a unique relationship id based on the current slide id.
                relId = "rel" + currentSlideId;

                // Get the bytes, type and size of the image.
                ImagePartType imagePartType = ImagePartType.Png;
                byte[]        imageBytes    = GetImageData(imageFileNameWithPath, ref imagePartType, ref imageWidthEMU, ref imageHeightEMU);

                // Create a slide part for the new slide.
                var slidePart = presentationPart.AddNewPart <SlidePart>(relId);
                GenerateSlidePart(imageFileNameNoPath, imageFileNameNoPath, imageWidthEMU, imageHeightEMU).Save(slidePart);

                // Add the relationship between the slide and the slide layout.
                slidePart.AddPart <SlideLayoutPart>(slideLayoutPart);

                // Create an image part for the image used by the new slide.
                // A hardcoded relationship id is used for the image part since
                // there is only one image per slide. If more than one image
                // was being added to the slide an approach similar to that
                // used above for the slide part relationship id could be
                // followed, where the image part relationship id could be
                // incremented for each image part.
                var imagePart = slidePart.AddImagePart(imagePartType, "relId1");
                GenerateImagePart(imagePart, imageBytes);

                // Add the new slide to the slide list.
                slideId = new SlideId();
                slideId.RelationshipId = relId;
                slideId.Id             = currentSlideId;
                presentationPart.Presentation.SlideIdList.Append(slideId);

                // Increment the slide id;
                currentSlideId++;
            }

            // Save the changes to the slide master part.
            slideMasterPart.SlideMaster.Save();

            // Save the changes to the new deck.
            presentationPart.Presentation.Save();
        }
    }
示例#28
0
    static void CreateSlides(List <string> imageFileNames, string newPresentation)
    {
        int           id = 0;
        string        relId;
        SlideId       newSlideId;
        SlideLayoutId newSlideLayoutId;

        string imageFileNameNoPath;

        long imageWidthEMU  = 0;
        long imageHeightEMU = 0;

        // Open the new presentation.
        using (PresentationDocument newDeck = PresentationDocument.Open(newPresentation, true))
        {
            // Get the presentation part of the new deck.
            PresentationPart presentationPart = newDeck.PresentationPart;

            // Reuse the slide master. Otherwise, create a new slide master part and a new theme part.
            var slideMasterPart = presentationPart.SlideMasterParts.First();

            // If the new presentation doesn't have a SlideIdList element yet then add it.
            if (presentationPart.Presentation.SlideIdList == null)
            {
                presentationPart.Presentation.SlideIdList = new SlideIdList();
            }

            // If the slide master doesn't have a SlideLayoutIdList element yet then add it.
            if (slideMasterPart.SlideMaster.SlideLayoutIdList == null)
            {
                slideMasterPart.SlideMaster.SlideLayoutIdList = new SlideLayoutIdList();
            }

            // Get a unique id for both the slide master id and slide layout id lists.
            uint uniqueId = GetMaxUniqueId(presentationPart);

            // Get a unique id for the slide id list.
            uint maxSlideId = GetMaxSlideId(presentationPart.Presentation.SlideIdList);

            // Loop through each file in the image folder creating slides in the new presentation.
            foreach (string imageFileNameWithPath in imageFileNames)
            {
                imageFileNameNoPath = Path.GetFileNameWithoutExtension(imageFileNameWithPath);

                // Create a unique relationship id based on the name of the image file.
                id++;
                relId = imageFileNameNoPath.Replace(" ", "") + id;

                // Get the bytes and size of the image.
                byte[] imageBytes = GetImageData(imageFileNameWithPath, ref imageWidthEMU, ref imageHeightEMU);

                // Create the new slide part.
                var slidePart = presentationPart.AddNewPart <SlidePart>(relId);
                GenerateSlidePart(relId, imageFileNameNoPath, imageFileNameNoPath, imageWidthEMU, imageHeightEMU).Save(slidePart);

                var imagePart = slidePart.AddImagePart(ImagePartType.Jpeg, relId);
                GenerateImagePart(imagePart, imageBytes);

                //slidePart.AddPart(slideLayoutPart);
                var slideLayoutPart = slidePart.AddNewPart <SlideLayoutPart>();
                GenerateSlideLayoutPart().Save(slideLayoutPart);

                slideMasterPart.AddPart(slideLayoutPart);
                slideLayoutPart.AddPart(slideMasterPart);

                // Add new slide layout into the list in slideMasterPart
                uniqueId++;
                newSlideLayoutId = new SlideLayoutId();
                newSlideLayoutId.RelationshipId = slideMasterPart.GetIdOfPart(slideLayoutPart);
                newSlideLayoutId.Id             = uniqueId;
                slideMasterPart.SlideMaster.SlideLayoutIdList.Append(newSlideLayoutId);

                // Add slide to slide list.
                maxSlideId++;
                newSlideId = new SlideId();
                newSlideId.RelationshipId = relId;
                newSlideId.Id             = maxSlideId;
                presentationPart.Presentation.SlideIdList.Append(newSlideId);
            }

            slideMasterPart.SlideMaster.Save();

            // Make sure all slide ids are unique.
            // FixSlideLayoutIds(presentationPart);

            // Save the changes to the new deck.
            presentationPart.Presentation.Save();
        }
    }
示例#29
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();
        }
示例#30
0
        private static SlidePart CreateSlidePart(PresentationPart presentationPart)
        {
            SlidePart slidePart1 = presentationPart.AddNewPart <SlidePart>("rId2"); // Add to slide list part.

            slidePart1.Slide = new Slide(
                new CommonSlideData(
                    new ShapeTree(
                        new P.NonVisualGroupShapeProperties(
                            new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)1U, Name = ""
            },
                            new P.NonVisualGroupShapeDrawingProperties(),
                            new ApplicationNonVisualDrawingProperties()),
                        new GroupShapeProperties(new Drawing.TransformGroup()),
                        new P.Shape(
                            new P.NonVisualShapeProperties(
                                new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)2U, Name = "Title 1"
            },
                                new P.NonVisualShapeDrawingProperties(new Drawing.ShapeLocks()
            {
                NoGrouping = true
            }),
                                new ApplicationNonVisualDrawingProperties(new PlaceholderShape())
                                ),
                            new P.ShapeProperties(),
                            new P.TextBody(
                                new Drawing.BodyProperties(),
                                new Drawing.ListStyle(),
                                new Drawing.Paragraph(new Drawing.EndParagraphRunProperties()
            {
                Language = "en-US"
            }))
                            )
                        )
                    ),
                new ColorMapOverride(new Drawing.MasterColorMapping())
                );

            /*
             * // TITLE. //
             * // Declare and instantiate the title shape of the new slide.
             * Shape titleShape = slidePart1.Slide.CommonSlideData.ShapeTree.AppendChild(new Shape());
             *
             * // Specify the required shape properties for the title shape.
             * titleShape.NonVisualShapeProperties = new NonVisualShapeProperties
             *  (new NonVisualDrawingProperties() { Id = (UInt32Value)3U, 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 = "This is the title!" })));
             *
             * // CONTENT. //
             * // Declare and instantiate the body shape of the new slide.
             * Shape bodyShape = slidePart1.Slide.CommonSlideData.ShapeTree.AppendChild(new Shape());
             *
             * // Specify the required shape properties for the body shape.
             * bodyShape.NonVisualShapeProperties = new NonVisualShapeProperties
             *  (new NonVisualDrawingProperties() { Id = (UInt32Value)4U, Name = "Content" },
             *  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(new Drawing.Run(new Drawing.Text() { Text = "This is the content!" })));
             */

            return(slidePart1);
        }