public ISlide InsertSlide(ISlideLayout slideLayout, int index) { if (!(slideLayout is IOpenXmlSlideLayout internalSlideLayout)) { throw new ArgumentException(); } Slide slide = new Slide() { // CommonSlideData = slideLayoutRef.SlideLayoutPart.SlideLayout.CommonSlideData.CloneNode(true) as CommonSlideData CommonSlideData = new CommonSlideData() { ShapeTree = new ShapeTree() { NonVisualGroupShapeProperties = internalSlideLayout.SlideLayoutPart.SlideLayout.CommonSlideData.ShapeTree.NonVisualGroupShapeProperties.CloneNode(true) as NonVisualGroupShapeProperties, GroupShapeProperties = internalSlideLayout.SlideLayoutPart.SlideLayout.CommonSlideData.ShapeTree.GroupShapeProperties.CloneNode(true) as GroupShapeProperties } } }; slide.CommonSlideData.ShapeTree.Append( internalSlideLayout.SlideLayoutPart.SlideLayout.CommonSlideData.ShapeTree .Select(element => OpenXmlVisualFactory.TryCreateVisual(internalSlideLayout, element, out IOpenXmlVisual visual) ? visual : null).Where(visual => visual != null) .Where(visual => visual?.IsPlaceholder ?? false) .Select(visual => visual.CloneForSlide()) ); SlidePart slidePart = this.presentationPart.AddNewPart <SlidePart>(); slide.Save(slidePart); slidePart.CreateRelationshipToPartDefaultId(internalSlideLayout.SlideLayoutPart); if (this.presentationPart.Presentation.SlideIdList == null) { this.presentationPart.Presentation.SlideIdList = new SlideIdList(); } SlideIdList slideIdList = this.presentationPart.Presentation.SlideIdList; SlideId refSlideId = slideIdList.Elements <SlideId>().Take(index).LastOrDefault(); uint id = refSlideId?.Id ?? 256; SlideId slideId; if (refSlideId != null) { slideId = slideIdList.InsertAfter( new SlideId() { Id = ++id, RelationshipId = presentationPart.GetIdOfPart(slidePart) }, refSlideId ); } else { slideId = slideIdList.PrependChild( new SlideId() { Id = ++id, RelationshipId = presentationPart.GetIdOfPart(slidePart) } ); } for (slideId = slideId.NextSibling <SlideId>(); slideId != null; slideId = slideId.NextSibling <SlideId>()) { slideId.Id = ++id; } return(new OpenXmlSlide(this, slidePart)); }