Hi,
I want to merge some pptx files into one.
Creating sections in base.pptx works.
Cloning slides works, slides go to section[0].
When I want to move recently copied slide to last created section I get an error:
System.IndexOutOfRangeException: „Index was out of range,value should be greater than slide count”
//base pptx has 'START' section and one slide inside it
IPresentation outputPptx = Presentation.Open(@"Z:\base.pptx");
IPresentation sourcePresentation;
//PptFilesSelectedCollection is a collection of selected files in sfDataGrid not mentioned here
foreach (object element in PptFilesSelectedCollection)
{
//PptFileModel.FullName is a path to the file, .SectionName is a section name PptFileModel file = element as PptFileModel; sourcePresentation = Presentation.Open(file.FullName); ISection section = outputPptx.Sections.Add(); section.Name = file.SectionName; foreach (ISlide sourceSlide in sourcePresentation.Slides) { ISlide clonedSlide = sourceSlide.Clone(); outputPptx.Slides.Add(clonedSlide, PasteOptions.SourceFormatting, outputPptx); ISlide slide = outputPptx.Sections[0].Slides[1]; // the error shows here //Moves the slide to last added section slide.MoveToSection(outputPptx.Sections.Count - 1); } sourcePresentation.Close();
}
outputPptx.Save(@"Z:\output.PPTX");
outputPptx.Close();
What do I do wrong?
|
foreach (ISlide sourceSlide in sourcePresentation.Slides) { ISlide clonedSlide = sourceSlide.Clone(); outputPptx.Sections[0].Slides.Add(clonedSlide, PasteOptions.SourceFormatting, outputPptx); } |
|
foreach (ISlide sourceSlide in sourcePresentation.Slides) { ISlide clonedSlide = sourceSlide.Clone(); outputPptx.Slides.Add(clonedSlide, PasteOptions.SourceFormatting, outputPptx); ISlide slide = outputPptx.Slides[0]; //Moves the slide to last added section slide.MoveToSection(0); } |