【发布时间】:2012-10-20 08:04:06
【问题描述】:
快速问题希望有人可以在这里提供帮助。我正在尝试将幻灯片从一个 powerpoint 演示文稿复制并粘贴到下一个演示文稿中。我目前有它,以便它将所有数量的幻灯片复制并粘贴到正确的幻灯片上,但我的问题是它只是一遍又一遍地粘贴在演示文稿的最后一张幻灯片上。我已经尝试了 for/foreach 循环,但只是给我一张幻灯片,我想知道它是否不是 CommandBars。但我看到它们被用来在 for/foreach 循环中重置幻灯片。有什么想法吗?
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);
}
}
【问题讨论】:
标签: c# vsto powerpoint