快速问题希望有人可以在这里帮忙。我试图将幻灯片从一个PowerPoint演示文稿复制并粘贴到下一个。我目前已经准备好了,因此它会将所有幻灯片的数量复制并粘贴到正确的幻灯片上,但是我的问题是,它只是一遍又一遍地粘贴演示文稿的最后一张幻灯片。我已经尝试了/ foreach循环,但只是给我一张幻灯片,我想知道它是不是CommandBars。但我发现它们被用于重置for/foreach循环中的幻灯片。有任何想法吗?C#VSTO-PowerPoint复制/粘贴幻灯片与源格式
public void AppendPPTX(string newContent)
{
int sourceSlideRange = 0;
int targetSlideRange = Application.ActiveWindow.Presentation.Slides.Count;
PowerPoint.Presentation target;
PowerPoint.Presentation source;
try
{
target = Application.ActivePresentation;
source = Application.Presentations.Open(newContent, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
sourceSlideRange = source.Slides.Count + 1; //otherwise I was just getting the second to the last slide
for (int i = 1; i < sourceSlideRange; i++)
{
source.Slides[i].Copy();
target.Slides[targetSlideRange].Select();
target.Application.CommandBars.ExecuteMso("PasteSourceFormatting");
}
source.Close();
}
catch (Exception)
{
MessageBox.Show("Error opening PowerPoint, corruption found inside the powerpoint file. " +
Environment.NewLine + "The corrupted file has been deleted." + Environment.NewLine +
"Please attempt to redownload file.",
"Error Opening PowerPoint",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
谢谢你解决了这个问题。 – KJones 2012-03-30 16:34:00