如何将一个 PowerPoint 演示文稿的特定幻灯片复制到另一个?
How to copy specific slides of one PowerPoint presentation to another?
我使用以下代码尝试将一个演示文稿的特定幻灯片复制到另一个演示文稿,但它没有发生,我也没有收到任何错误。
source = ppt.Presentations.Open(filename, MsoTriState.msoTrue,
MsoTriState.msoTrue, MsoTriState.msoTrue);
target = ppt.Presentations.Open(targetname, MsoTriState.msoTrue,
MsoTriState.msoTrue, MsoTriState.msoTrue);
sourceSlideRange = source.Slides.Count;
for (int i = 3; i < sourceSlideRange; i++)
{
source.Slides[i].Copy();
target.Windows[1].Activate();
target.Slides[1].Select();
target.Application.CommandBars.ExecuteMso("PasteSourceFormatting");
}
我的代码有什么问题?请suggest.Thanks
由于我的要求是只在演示文稿中保留特定的幻灯片,而我发布的复制代码不起作用,所以我尝试从演示文稿中删除不需要的幻灯片,只保留我需要的幻灯片。下面是解决目的的代码
Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
ppt.Visible = MsoTriState.msoTrue;
ppt.WindowState = Microsoft.Office.Interop.PowerPoint.PpWindowState.ppWindowMinimized;
source = ppt.Presentations.Open(filename);
target = ppt.Presentations.Open(targetname, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue);
sourceSlideRange = source.Slides.Count;
for (int i = 3; i < sourceSlideRange; i++)
{
source.Slides[i].Delete();
source.Save();
}
source.Close();
我使用以下代码尝试将一个演示文稿的特定幻灯片复制到另一个演示文稿,但它没有发生,我也没有收到任何错误。
source = ppt.Presentations.Open(filename, MsoTriState.msoTrue,
MsoTriState.msoTrue, MsoTriState.msoTrue);
target = ppt.Presentations.Open(targetname, MsoTriState.msoTrue,
MsoTriState.msoTrue, MsoTriState.msoTrue);
sourceSlideRange = source.Slides.Count;
for (int i = 3; i < sourceSlideRange; i++)
{
source.Slides[i].Copy();
target.Windows[1].Activate();
target.Slides[1].Select();
target.Application.CommandBars.ExecuteMso("PasteSourceFormatting");
}
我的代码有什么问题?请suggest.Thanks
由于我的要求是只在演示文稿中保留特定的幻灯片,而我发布的复制代码不起作用,所以我尝试从演示文稿中删除不需要的幻灯片,只保留我需要的幻灯片。下面是解决目的的代码
Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
ppt.Visible = MsoTriState.msoTrue;
ppt.WindowState = Microsoft.Office.Interop.PowerPoint.PpWindowState.ppWindowMinimized;
source = ppt.Presentations.Open(filename);
target = ppt.Presentations.Open(targetname, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoTrue);
sourceSlideRange = source.Slides.Count;
for (int i = 3; i < sourceSlideRange; i++)
{
source.Slides[i].Delete();
source.Save();
}
source.Close();