Пример #1
0
        internal SCSlideLayout GetSlideLayoutBySlide(SCSlide slide)
        {
            SlideLayoutPart inputSlideLayoutPart = slide.SlidePart.SlideLayoutPart;

            return(CollectionItems.SelectMany(sm => sm.SlideLayouts)
                   .First(sl => sl.SlideLayoutPart == inputSlideLayoutPart));
        }
Пример #2
0
        internal static void AppendSlideMaster(PresentationPart presentationPart, SlideMaster slideMaster, IEnumerable <SlideLayout> slideLayouts)
        {
            // append a new SlideMasterPart
            SlideMasterPart slideMasterPart = presentationPart.AddNewPartDefaultId <SlideMasterPart>();

            // clear SlideLayoutIdList and rebuild it
            slideMaster.SlideLayoutIdList = new SlideLayoutIdList();

            foreach (SlideLayout slideLayout in slideLayouts)
            {
                SlideLayoutPart slideLayoutPart = slideMasterPart.AddNewPartDefaultId <SlideLayoutPart>(out string slideLayoutPartId);
                slideLayoutPart.CreateRelationshipToPartDefaultId(slideMasterPart);
                slideLayout.Save(slideLayoutPart);

                // add to SlideLayoutIdList
                slideMaster.SlideLayoutIdList.AppendChild(new SlideLayoutId()
                {
                    Id             = slideMaster.SlideLayoutIdList.Elements <SlideLayoutId>().Select(sl => sl.Id.Value).DefaultIfEmpty(2147483648u).Max() + 1,
                    RelationshipId = slideMasterPart.GetIdOfPart(slideLayoutPart)
                });
            }

            slideMasterPart.CreateRelationshipToPartDefaultId(presentationPart.ThemePart);
            slideMaster.Save(slideMasterPart);

            AddSlideMasterToSlideMasterIdList(presentationPart, slideMasterPart);
        }
Пример #3
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));
        }
Пример #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));
        }
Пример #5
0
        override public void Apply(RegularContainer pmaster)
        {
            Slide master = (Slide)pmaster;

            TraceLogger.DebugInternal("MasterMapping.Apply");
            UInt32 masterId = master.PersistAtom.SlideId;

            _ctx.RegisterMasterMapping(masterId, this);

            this.Master        = master;
            this.MasterId      = master.PersistAtom.SlideId;
            this.LayoutManager = _ctx.GetOrCreateLayoutManagerByMasterId(this.MasterId);

            // Add PPT2007 roundtrip slide layouts
            List <RoundTripContentMasterInfo12> rtSlideLayouts = this.Master.AllChildrenWithType <RoundTripContentMasterInfo12>();

            foreach (RoundTripContentMasterInfo12 slideLayout in rtSlideLayouts)
            {
                SlideLayoutPart layoutPart = this.LayoutManager.AddLayoutPartWithInstanceId(slideLayout.Instance);
                XmlNode         e          = slideLayout.XmlDocumentElement;

                XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
                nsm.AddNamespace("a", OpenXmlNamespaces.DrawingML);

                //for the moment remove blips that reference pictures
                foreach (XmlNode bublip in  e.SelectNodes("//a:buBlip", nsm))
                {
                    bublip.ParentNode.RemoveChild(bublip);
                }

                Tools.Utils.replaceOutdatedNamespaces(ref e);
                e.WriteTo(layoutPart.XmlWriter);
                layoutPart.XmlWriter.Flush();
            }
        }
Пример #6
0
 internal SCSlideLayout(SCSlideMaster slideMaster, SlideLayoutPart sldLayoutPart)
 {
     _slideMaster    = slideMaster;
     SlideLayoutPart = sldLayoutPart;
     _shapes         = new ResettableLazy <ShapeCollection>(() =>
                                                            ShapeCollection.CreateForSlideLayout(sldLayoutPart.SlideLayout.CommonSlideData.ShapeTree, this));
 }
        private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1)
        {
            SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart <SlideLayoutPart>("rId1");
            SlideLayout     slideLayout      = new SlideLayout(
                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 EndParagraphRunProperties()))))),
                new ColorMapOverride(new MasterColorMapping()));

            slideLayoutPart1.SlideLayout = slideLayout;
            slideLayoutPart1.SlideLayout.CommonSlideData.Name = "ChartsSlideLayout";
            return(slideLayoutPart1);
        }
Пример #8
0
        private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1)
        {
            SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart <SlideLayoutPart>("rId1");

            P.SlideLayout slideLayout = new P.SlideLayout(
                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 = string.Empty
            },
                                                  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()))))),
                new P.ColorMapOverride(new D.MasterColorMapping()));
            slideLayoutPart1.SlideLayout = slideLayout;
            return(slideLayoutPart1);
        }
Пример #9
0
        public SlideLayoutPart AddSlideLayoutPart()
        {
            var part = new SlideLayoutPart(this, ++_slideLayoutCounter);

            part.ReferencePart(this);
            return(this.AddPart(part));
        }
Пример #10
0
        public SlideLayoutPart AddLayoutPartWithInstanceId(UInt32 instanceId)
        {
            SlideMasterPart masterPart = _ctx.GetOrCreateMasterMappingByMasterId(this.MasterId).MasterPart;
            SlideLayoutPart layoutPart = masterPart.AddSlideLayoutPart();

            this.InstanceIdToLayoutPart.Add(instanceId, layoutPart);
            return(layoutPart);
        }
Пример #11
0
        // Get the slide layout type.
        public static string GetSlideLayoutType(SlideLayoutPart slideLayoutPart)
        {
            CommonSlideData slideData = slideLayoutPart.SlideLayout.CommonSlideData;

            // Remarks: If this is used in production code, check for a null reference.

            return(slideData.Name);
        }
        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);
        }
Пример #13
0
        /// <summary>
        /// Lấy chủ đề
        /// </summary>
        /// <param name="design"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public ETheme GetETheme(pp.Design design, int count)
        {
            ETheme etheme = new ETheme();

            etheme.Name      = design.Name;
            etheme.ID        = ObjectElementsHelper.RandomString(10);
            etheme.ThemeName = design.Name;
            EColorManagment eColorManagment = new EColorManagment();

            eColorManagment     = GetEColorManagment(design.SlideMaster.Theme.ThemeColorScheme);
            etheme.Colors       = eColorManagment;
            etheme.SelectedFont = GetFontTheme(design.SlideMaster.Theme.ThemeFontScheme);
            ESlideMaster eSlideMaster = new ESlideMaster();

            eSlideMaster.ThemesName = etheme.Name;
            eSlideMaster.Name       = etheme.Name;
            eSlideMaster.MainLayer  = new PageLayer();
            SlideMasterPart slideMasterPart = GetSlideMasterPart(count);

            eSlideMaster.MainLayer.Background = GetFillColorSlideMaster(design.SlideMaster.Background.Fill, slideMasterPart.SlideMaster?.CommonSlideData, slideMasterPart);
            eSlideMaster.ID = ObjectElementsHelper.RandomString(12);
            foreach (pp.Shape shape in design.SlideMaster.Shapes)
            {
                eSlideMaster.MainLayer.Children.Add(GetShape(shape, shape.Type, design.SlideMaster.TimeLine, slideMasterPart));
            }
            SetIsBackgroundShape(eSlideMaster.MainLayer);

            int countLayoutMaster = 0;

            foreach (pp.CustomLayout layout in design.SlideMaster.CustomLayouts)
            {
                SlideLayoutPart slideLayoutPart = GetSlideLayoutPart(countLayoutMaster++, slideMasterPart);
                ELayoutMaster   eLayoutMaster   = new ELayoutMaster();
                eLayoutMaster.ID                   = ObjectElementsHelper.RandomString(13);
                eLayoutMaster.MainLayer            = new PageLayer();
                eLayoutMaster.MainLayer.Background = GetFillColorSlideMaster(layout.Background.Fill, slideLayoutPart.SlideLayout?.CommonSlideData, slideLayoutPart);
                if (eLayoutMaster.MainLayer.Background == null)
                {
                    eLayoutMaster.MainLayer.Background = eSlideMaster.MainLayer.Background;
                }
                foreach (pp.Shape shape in layout.Shapes)
                {
                    eLayoutMaster.MainLayer.Children.Add(GetShape(shape, shape.Type, design.SlideMaster.TimeLine, slideLayoutPart));
                }
                SetIsBackgroundShape(eLayoutMaster.MainLayer);
                eLayoutMaster.SlideName        = layout.Name;
                eLayoutMaster.LayoutName       = layout.Name;
                eLayoutMaster.IsHideBackground = layout.DisplayMasterShapes != MsoTriState.msoTrue;

                eSlideMaster.LayoutMasters.Add(eLayoutMaster);
            }

            etheme.SlideMasters.Add(eSlideMaster);
            return(etheme);
        }
Пример #14
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);
        }
Пример #15
0
        private void insert(PresentationPart presentationPart, List <String> imgList)
        {
            int  idx        = 1;
            uint uid        = UInt32.MaxValue;
            var  slideParts = presentationPart.SlideParts;

            string            slideMasterRid    = "rId" + idx;
            SlideMasterIdList slideMasterIdList = new SlideMasterIdList(new SlideMasterId()
            {
                Id = uid, RelationshipId = slideMasterRid
            });
            SlideIdList slideIdList = new SlideIdList();
            SlideSize   slideSize   = new SlideSize()
            {
                Cx = 9144000, Cy = 6858000, Type = SlideSizeValues.Screen4x3
            };
            NotesSize notesSize = new NotesSize()
            {
                Cx = 6858000, Cy = 9144000
            };
            DefaultTextStyle defaultTextStyle = new DefaultTextStyle();

            presentationPart.Presentation.Append(slideMasterIdList, slideIdList, slideSize, notesSize, defaultTextStyle);

            SlideLayoutPart layoutPart = null;
            SlideMasterPart masterPart = null;
            ThemePart       themePart  = null;

            foreach (string imgPath in imgList)
            {
                String imgIdx   = "rId" + (900 + idx);
                String slideIdx = "rId" + (idx + 1);
                String themeIdx = "rId" + (idx + 4);

                var slidePart = CreateSlidePart(presentationPart, slideIdx, uid = uid - 10);
                if (null == layoutPart)
                {
                    layoutPart = CreateSlideLayoutPart(slidePart, slideMasterRid, uid = uid - 10);
                    masterPart = CreateSlideMasterPart(layoutPart, slideMasterRid, uid = uid - 10);
                    themePart  = CreateTheme(masterPart, themeIdx);
                    masterPart.AddPart(layoutPart, slideMasterRid);
                    presentationPart.AddPart(masterPart, slideMasterRid);
                    presentationPart.AddPart(themePart, themeIdx);
                }

                //insert(slidePart, imgPath, imgIdx, uid = uid - 10);
                idx += 5;
            }
            presentationPart.Presentation.Save();
        }
Пример #16
0
        public SlideLayoutPart GetOrCreateLayoutPartForTitleMasterId(UInt32 titleMasterId)
        {
            SlideMasterPart masterPart = _ctx.GetOrCreateMasterMappingByMasterId(this.MasterId).MasterPart;

            if (!this.TitleMasterIdToLayoutPart.ContainsKey(titleMasterId))
            {
                Slide           titleMaster = _ctx.Ppt.FindMasterRecordById(titleMasterId);
                SlideLayoutPart layoutPart  = masterPart.AddSlideLayoutPart();
                new TitleMasterMapping(_ctx, layoutPart).Apply(titleMaster);
                this.TitleMasterIdToLayoutPart.Add(titleMasterId, layoutPart);
            }

            return(this.TitleMasterIdToLayoutPart[titleMasterId]);
        }
Пример #17
0
        private static SlideMasterPart CreateSlideMasterPart(SlideLayoutPart slideLayoutPart1)
        {
            SlideMasterPart slideMasterPart1 = slideLayoutPart1.AddNewPart <SlideMasterPart>("rId1");
            SlideMaster     slideMaster      = new SlideMaster(
                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 Placeholder 1"
            },
                                                new P.NonVisualShapeDrawingProperties(new ShapeLocks()
            {
                NoGrouping = true
            }),
                                                new ApplicationNonVisualDrawingProperties(new PlaceholderShape()
            {
                Type = PlaceholderValues.Title
            })),
                                            new P.ShapeProperties(),
                                            new P.TextBody(
                                                new BodyProperties(),
                                                new ListStyle(),
                                                new Paragraph(new D.Run(new D.Text()
            {
                Text = "Create slide Master This presentation has been created by Kashish Jhaveri"
            })))))),
                new P.ColorMap()
            {
                Background1 = D.ColorSchemeIndexValues.Light1, Text1 = D.ColorSchemeIndexValues.Dark1, Background2 = D.ColorSchemeIndexValues.Light2, Text2 = D.ColorSchemeIndexValues.Dark2, Accent1 = D.ColorSchemeIndexValues.Accent1, Accent2 = D.ColorSchemeIndexValues.Accent2, Accent3 = D.ColorSchemeIndexValues.Accent3, Accent4 = D.ColorSchemeIndexValues.Accent4, Accent5 = D.ColorSchemeIndexValues.Accent5, Accent6 = D.ColorSchemeIndexValues.Accent6, Hyperlink = D.ColorSchemeIndexValues.Hyperlink, FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink
            },
                new SlideLayoutIdList(new SlideLayoutId()
            {
                Id = (UInt32Value)2147483649U, RelationshipId = "rId1"
            }),
                new TextStyles(new TitleStyle(), new BodyStyle(), new OtherStyle()));

            slideMasterPart1.SlideMaster = slideMaster;

            return(slideMasterPart1);
        }
Пример #18
0
        private void Init(SlideLayoutPart sldLtPart)
        {
            // Get OpenXmlCompositeElement instances have P.ShapeProperties
            var layoutElements = sldLtPart.SlideLayout.CommonSlideData.ShapeTree.Elements <OpenXmlCompositeElement>();
            var masterElements = sldLtPart.SlideMasterPart.SlideMaster.CommonSlideData.ShapeTree.Elements <OpenXmlCompositeElement>();
            var layoutHolders  = GetPlaceholders(layoutElements);
            var masterHolders  = GetPlaceholders(masterElements);

            // slide master can contain duplicate
            foreach (var mHolder in masterHolders.Where(mHolder => !layoutHolders.Contains(mHolder)))
            {
                layoutHolders.Add(mHolder);
            }
            _phLocations = layoutHolders.ToHashSet(); //TODO: optimize ToHashSet()
        }
Пример #19
0
        private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart, string layoutIdx, uint uid)
        {
            SlideLayoutPart layoutPart  = slidePart.AddNewPart <SlideLayoutPart>(layoutIdx);
            SlideLayout     slideLayout = new SlideLayout(new CommonSlideData(new ShapeTree(
                                                                                  new P.NonVisualGroupShapeProperties(
                                                                                      new P.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)1U, Name = ""
            },
                                                                                      new P.NonVisualGroupShapeDrawingProperties(),
                                                                                      new ApplicationNonVisualDrawingProperties()),
                                                                                  new GroupShapeProperties(new TransformGroup()))));

            layoutPart.SlideLayout = slideLayout;
            return(layoutPart);
        }
Пример #20
0
        public SlideLayoutPart GetOrCreateLayoutPartByCode(string xml)
        {
            SlideMasterPart masterPart = _ctx.GetOrCreateMasterMappingByMasterId(this.MasterId).MasterPart;

            if (!this.CodeToLayoutPart.ContainsKey(xml))
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);

                SlideLayoutPart layoutPart = masterPart.AddSlideLayoutPart();
                doc.WriteTo(layoutPart.XmlWriter);
                layoutPart.XmlWriter.Flush();
                CodeToLayoutPart.Add(xml, layoutPart);
            }

            return(CodeToLayoutPart[xml]);
        }
Пример #21
0
        private static SlideMasterPart CreateSlideMasterPart(SlideLayoutPart slideLayoutPart1)
        {
            SlideMasterPart slideMasterPart1 = slideLayoutPart1.AddNewPart <SlideMasterPart>("rId1");

            P.SlideMaster slideMaster = new P.SlideMaster(
                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 Placeholder 1"
            },
                                                  new P.NonVisualShapeDrawingProperties(new D.ShapeLocks()
            {
                NoGrouping = true
            }),
                                                  new P.ApplicationNonVisualDrawingProperties(new P.PlaceholderShape()
            {
                Type = P.PlaceholderValues.Title
            })),
                                              new P.ShapeProperties(),
                                              new P.TextBody(
                                                  new D.BodyProperties(),
                                                  new D.ListStyle(),
                                                  new D.Paragraph())))),
                new P.ColorMap()
            {
                Background1 = D.ColorSchemeIndexValues.Light1, Text1 = D.ColorSchemeIndexValues.Dark1, Background2 = D.ColorSchemeIndexValues.Light2, Text2 = D.ColorSchemeIndexValues.Dark2, Accent1 = D.ColorSchemeIndexValues.Accent1, Accent2 = D.ColorSchemeIndexValues.Accent2, Accent3 = D.ColorSchemeIndexValues.Accent3, Accent4 = D.ColorSchemeIndexValues.Accent4, Accent5 = D.ColorSchemeIndexValues.Accent5, Accent6 = D.ColorSchemeIndexValues.Accent6, Hyperlink = D.ColorSchemeIndexValues.Hyperlink, FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink
            },
                new P.SlideLayoutIdList(new P.SlideLayoutId()
            {
                Id = 2147483649U, RelationshipId = "rId1"
            }),
                new P.TextStyles(new P.TitleStyle(), new P.BodyStyle(), new P.OtherStyle()));
            slideMasterPart1.SlideMaster = slideMaster;

            return(slideMasterPart1);
        }
        /// <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));
        }
Пример #23
0
        private static SlideLayoutPart CreateSlideLayoutPart(SlidePart slidePart1)
        {
            SlideLayoutPart slideLayoutPart1 = slidePart1.AddNewPart <SlideLayoutPart>("rId1"); // Add to slide master list part.
            SlideLayout     slideLayout      = new SlideLayout(
                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 = ""
            },
                                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()))
                            )
                        )
                    ),
                new ColorMapOverride(new Drawing.MasterColorMapping())
                )
            {
                Type = SlideLayoutValues.Title
            };

            slideLayoutPart1.SlideLayout      = slideLayout;
            slideLayoutPart1.SlideLayout.Type = SlideLayoutValues.Title;
            return(slideLayoutPart1);
        }
Пример #24
0
        public static void CreatePresentationPart(PresentationPart part, PPTXSetting FileSettings, PPTXSlideLayoutGroup SlideLayouts)
        {
            var partCreator = new DefaultPresentationPart();

            partCreator._CreatePresentationPart(part);

            SlidePart slidePart1 = DefaultSlidePart.CreateSlidePart(part, "rId2", FileSettings);

            // 1枚目のスライド追加
            var topLayoutPart = new SlideLayout_TitleSlide();

            topLayoutPart.Init(EPPTXSlideLayoutType.TitleSlide, SlideLayouts);
            SlideLayoutPart slideLayoutPart1 = topLayoutPart.CreateSlideLayoutPart(slidePart1);
            SlideMasterPart slideMasterPart1 = DefaultSlideMasterPart.CreateSlideMasterPart(slideLayoutPart1, "rId1");
            ThemePart       themePart1       = DefaultTheme.CreateTheme(slideMasterPart1);

            slideMasterPart1.AddPart(slideLayoutPart1, "rId1");
            part.AddPart(slideMasterPart1, "rId1");
            part.AddPart(themePart1, "rId5");

            // 残りのスライドレイアウトを追加
            foreach (EPPTXSlideLayoutType layoutType in Enum.GetValues(typeof(EPPTXSlideLayoutType)))
            {
                if (layoutType == EPPTXSlideLayoutType.TitleSlide)
                {
                    continue;
                }

                var otherLayoutPartType = Type.GetType($"MDToPPTX.PPTX.DefaultParts.SlideLayouts.SlideLayout_{layoutType.ToString()}");
                if (otherLayoutPartType == null)
                {
                    continue;
                }
                SlideLayoutPartBase otherLayoutPart = Activator.CreateInstance(otherLayoutPartType) as SlideLayoutPartBase;
                if (otherLayoutPart != null)
                {
                    otherLayoutPart.Init(layoutType, SlideLayouts);
                    SlideLayoutPart otherSlideLayoutPart = otherLayoutPart.CreateSlideLayoutPart(slideMasterPart1);

                    otherSlideLayoutPart.AddPart(slideMasterPart1, "rId1");
                }
            }
        }
Пример #25
0
        public SlideLayoutPart GetOrCreateLayoutPartByLayoutType(SlideLayoutType type,
                                                                 PlaceholderEnum[] placeholderTypes)
        {
            SlideMasterPart masterPart     = _ctx.GetOrCreateMasterMappingByMasterId(this.MasterId).MasterPart;
            string          layoutFilename = Utils.SlideLayoutTypeToFilename(type, placeholderTypes);


            if (!this.LayoutFilenameToLayoutPart.ContainsKey(layoutFilename))
            {
                XmlDocument slideLayoutDoc = Utils.GetDefaultDocument("slideLayouts." + layoutFilename);

                SlideLayoutPart layoutPart = masterPart.AddSlideLayoutPart();
                slideLayoutDoc.WriteTo(layoutPart.XmlWriter);
                layoutPart.XmlWriter.Flush();

                this.LayoutFilenameToLayoutPart.Add(layoutFilename, layoutPart);
            }

            return(this.LayoutFilenameToLayoutPart[layoutFilename]);
        }
Пример #26
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));
        }
Пример #27
0
 public OpenXmlSlideLayout(IOpenXmlPresentation presentation, SlideLayoutPart slideLayoutPart)
 {
     this.presentation    = presentation;
     this.slideLayoutPart = slideLayoutPart;
 }
Пример #28
0
 public PlaceholderLocationService(SlideLayoutPart sldLtPart)
 {
     Check.NotNull(sldLtPart, nameof(sldLtPart));
     Init(sldLtPart);
 }
Пример #29
0
        override public void Apply(RegularContainer slide)
        {
            this.Slide = (Slide)slide;
            TraceLogger.DebugInternal("SlideMapping.Apply");

            // Associate slide with slide layout
            var  slideAtom     = slide.FirstChildWithType <SlideAtom>();
            uint mainMasterId  = GetMainMasterId(slideAtom);
            var  layoutManager = this._ctx.GetOrCreateLayoutManagerByMasterId(mainMasterId);

            SlideLayoutPart layoutPart = null;
            var             masterInfo = slide.FirstChildWithType <RoundTripContentMasterId12>();

            // PPT2007 OOXML-Layout
            if (masterInfo != null)
            {
                layoutPart = layoutManager.GetLayoutPartByInstanceId(masterInfo.ContentMasterInstanceId);
            }
            // Pre-PPT2007 Title master layout
            else if (mainMasterId != slideAtom.MasterId)
            {
                layoutPart = layoutManager.GetOrCreateLayoutPartForTitleMasterId(slideAtom.MasterId);
            }
            // Pre-PPT2007 SSlideLayoutAtom primitive SlideLayoutType layout
            else
            {
                var m = (MainMaster)this._ctx.Ppt.FindMasterRecordById(slideAtom.MasterId);
                if (m.Layouts.Count == 1 && slideAtom.Layout.Geom == SlideLayoutType.Blank)
                {
                    foreach (string layout in m.Layouts.Values)
                    {
                        string output = Tools.Utils.replaceOutdatedNamespaces(layout);
                        layoutPart = layoutManager.GetOrCreateLayoutPartByCode(output);
                    }
                }
                else
                {
                    layoutPart = layoutManager.GetOrCreateLayoutPartByLayoutType(slideAtom.Layout.Geom, slideAtom.Layout.PlaceholderTypes);
                }
            }

            this.targetPart.ReferencePart(layoutPart);

            // Start the document
            this._writer.WriteStartDocument();
            this._writer.WriteStartElement("p", "sld", OpenXmlNamespaces.PresentationML);

            // Force declaration of these namespaces at document start
            this._writer.WriteAttributeString("xmlns", "a", null, OpenXmlNamespaces.DrawingML);
            // Force declaration of these namespaces at document start
            this._writer.WriteAttributeString("xmlns", "r", null, OpenXmlNamespaces.Relationships);


            if (Tools.Utils.BitmaskToBool(slideAtom.Flags, 0x1 << 0) == false)
            {
                this._writer.WriteAttributeString("showMasterSp", "0");
            }

            // TODO: Write slide data of master slide
            this._writer.WriteStartElement("p", "cSld", OpenXmlNamespaces.PresentationML);

            var sc = slide.FirstChildWithType <PPDrawing>().FirstChildWithType <DrawingContainer>().FirstChildWithType <ShapeContainer>();

            if (sc != null)
            {
                var sh = sc.FirstChildWithType <Shape>();
                var so = sc.FirstChildWithType <ShapeOptions>();

                if (so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.FillStyleBooleanProperties))
                {
                    bool ignore = false;
                    if (sc.AllChildrenWithType <ShapeOptions>().Count > 1)
                    {
                        var so2 = sc.AllChildrenWithType <ShapeOptions>()[1];
                        if (so2.OptionsByID.ContainsKey(ShapeOptions.PropertyId.FillStyleBooleanProperties))
                        {
                            var p2 = new FillStyleBooleanProperties(so2.OptionsByID[ShapeOptions.PropertyId.FillStyleBooleanProperties].op);
                            if (!p2.fUsefFilled || !p2.fFilled)
                            {
                                ignore = true;
                            }
                        }
                    }

                    var sa = slide.FirstChildWithType <SlideAtom>();
                    if (Tools.Utils.BitmaskToBool(sa.Flags, 0x1 << 2))
                    {
                        ignore = true;                                                //this means the slide gets its background from the master
                    }
                    if (!ignore)
                    {
                        this._writer.WriteStartElement("p", "bg", OpenXmlNamespaces.PresentationML);
                        this._writer.WriteStartElement("p", "bgPr", OpenXmlNamespaces.PresentationML);
                        var p = new FillStyleBooleanProperties(so.OptionsByID[ShapeOptions.PropertyId.FillStyleBooleanProperties].op);
                        if (p.fUsefFilled & p.fFilled) //  so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.fillType))
                        {
                            new FillMapping(this._ctx, this._writer, this).Apply(so);
                        }
                        this._writer.WriteElementString("a", "effectLst", OpenXmlNamespaces.DrawingML, "");
                        this._writer.WriteEndElement(); //p:bgPr
                        this._writer.WriteEndElement(); //p:bg
                    }
                }
            }


            this._writer.WriteStartElement("p", "spTree", OpenXmlNamespaces.PresentationML);

            this.shapeTreeMapping = new ShapeTreeMapping(this._ctx, this._writer);
            this.shapeTreeMapping.parentSlideMapping = this;
            this.shapeTreeMapping.Apply(slide.FirstChildWithType <PPDrawing>());

            checkHeaderFooter(this.shapeTreeMapping);

            this._writer.WriteEndElement(); //spTree
            this._writer.WriteEndElement(); //cSld

            // TODO: Write clrMapOvr

            if (slide.FirstChildWithType <SlideShowSlideInfoAtom>() != null)
            {
                new SlideTransitionMapping(this._ctx, this._writer).Apply(slide.FirstChildWithType <SlideShowSlideInfoAtom>());
            }

            if (slide.FirstChildWithType <ProgTags>() != null)
            {
                if (slide.FirstChildWithType <ProgTags>().FirstChildWithType <ProgBinaryTag>() != null)
                {
                    if (slide.FirstChildWithType <ProgTags>().FirstChildWithType <ProgBinaryTag>().FirstChildWithType <ProgBinaryTagDataBlob>() != null)
                    {
                        new AnimationMapping(this._ctx, this._writer).Apply(slide.FirstChildWithType <ProgTags>().FirstChildWithType <ProgBinaryTag>().FirstChildWithType <ProgBinaryTagDataBlob>(), this, this.shapeTreeMapping.animinfos, this.shapeTreeMapping);
                    }
                }
            }


            // End the document
            this._writer.WriteEndElement(); //sld
            this._writer.WriteEndDocument();

            this._writer.Flush();
        }
Пример #30
0
        // Apply a new theme to the presentation.
        public static void ApplyThemeToPresentation(PresentationDocument presentationDocument, PresentationDocument themeDocument)
        {
            if (presentationDocument == null)
            {
                throw new ArgumentNullException("presentationDocument");
            }
            if (themeDocument == null)
            {
                throw new ArgumentNullException("themeDocument");
            }

            // Get the presentation part of the presentation document.
            PresentationPart presentationPart = presentationDocument.PresentationPart;

            // Get the existing slide master part.
            SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.ElementAt(0);
            string          relationshipId  = presentationPart.GetIdOfPart(slideMasterPart);

            // Get the new slide master part.
            SlideMasterPart newSlideMasterPart = themeDocument.PresentationPart.SlideMasterParts.ElementAt(0);

            // Remove the existing theme part.
            presentationPart.DeletePart(presentationPart.ThemePart);

            // Remove the old slide master part.
            presentationPart.DeletePart(slideMasterPart);

            // Import the new slide master part, and reuse the old relationship ID.
            newSlideMasterPart = presentationPart.AddPart(newSlideMasterPart, relationshipId);

            // Change to the new theme part.
            presentationPart.AddPart(newSlideMasterPart.ThemePart);

            Dictionary <string, SlideLayoutPart> newSlideLayouts = new Dictionary <string, SlideLayoutPart>();

            foreach (var slideLayoutPart in newSlideMasterPart.SlideLayoutParts)
            {
                newSlideLayouts.Add(GetSlideLayoutType(slideLayoutPart), slideLayoutPart);
            }

            string          layoutType    = null;
            SlideLayoutPart newLayoutPart = null;

            // Insert the code for the layout for this example.
            string defaultLayoutType = "Title and Content";

            // Remove the slide layout relationship on all slides.
            foreach (var slidePart in presentationPart.SlideParts)
            {
                layoutType = null;

                if (slidePart.SlideLayoutPart != null)
                {
                    // Determine the slide layout type for each slide.
                    layoutType = GetSlideLayoutType(slidePart.SlideLayoutPart);

                    // Delete the old layout part.
                    slidePart.DeletePart(slidePart.SlideLayoutPart);
                }

                if (layoutType != null && newSlideLayouts.TryGetValue(layoutType, out newLayoutPart))
                {
                    // Apply the new layout part.
                    slidePart.AddPart(newLayoutPart);
                }
                else
                {
                    newLayoutPart = newSlideLayouts[defaultLayoutType];

                    // Apply the new default layout part.
                    slidePart.AddPart(newLayoutPart);
                }
            }
        }