Below is the code I used for this:
- Code: Select all
public void CopyShape()
{
Presentation ppt = new Presentation();
ppt.LoadFromFile(FILEPATH);
var shapeSlides = new List<ShapeSlides>();
int i = 0;
foreach (ISlide slide in ppt.Slides)
{
var shapes = slide.Shapes.ToArray();
if (shapes.Any())
{
var shapeSlide =
new ShapeSlides
{
SlideIndex = i
};
shapes.ToList().ForEach(t => { shapeSlide.Shapes.Add(t); });
shapeSlides.Add(shapeSlide);
}
i++;
}
Presentation pptout = new Presentation();
foreach (var shapeSlide in shapeSlides)
{
var slide = pptout.Slides.Append();
foreach (IShape shape in shapeSlide.Shapes)
{
if (shape != null)
{
slide.Shapes.AddShape((Shape)shape);
}
ppt.Slides[shapeSlide.SlideIndex].Shapes.Remove(shape);
}
}
pptout.SaveToFile(FILEPATHOUT2, FileFormat.Auto);
ppt.SaveToFile(FILEPATHOUT, FileFormat.Auto);
}
The ShapeSlides class
- Code: Select all
public class ShapeSlides
{
public int SlideIndex { get; set; }
public List<IShape> Shapes { get; set; } = new List<IShape>();
}
Thanks!