ppt保存幻灯片时保留源模板

Retain the source template when saving slides in ppt

我正在尝试保存选定的幻灯片,因此它不会保留我的源模板。我如何在保存幻灯片时保留现有模板

   private void SaveSelectedSlide_Click(object sender, RibbonControlEventArgs e)
    {
        try
        {
            PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
            PowerPoint.SlideRange ppslr = ppApp.ActiveWindow.Selection.SlideRange;
            string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var temporaryPresentation = Globals.ThisAddIn.Application.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
            Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = ppApp.ActivePresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

            for (int i = 1; i <= ppslr.Count; i++)
            {
                var sourceSlide = ppslr[i];
                sourceSlide.Copy();

                var design = sourceSlide.Design;
                temporaryPresentation.Slides.Paste();


            }

            temporaryPresentation.SaveAs("Temporary", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoTrue);

            temporaryPresentation.Close();

        }
        catch (COMException Ex)
        {
            Debug.WriteLine("Some problem" + Ex.Message + Ex.StackTrace);
            MessageBox.Show("PLease enter text ");
        }

    }

我想我得到了你想要的。粘贴新幻灯片时,保存新 SlideRange。然后 分配 源幻灯片设计

PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
PowerPoint.SlideRange ppslr = ppApp.ActiveWindow.Selection.SlideRange;
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var temporaryPresentation = Globals.ThisAddIn.Application.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = ppApp.ActivePresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

for (int i = 1; i <= ppslr.Count; i++)
{
    var sourceSlide = ppslr[i];
    sourceSlide.Copy();

    var design = sourceSlide.Design;                    
    SlideRange sr = temporaryPresentation.Slides.Paste(); // get newly created slideRange
    sr.Design = sourceSlide.Design; // manually set design
}
temporaryPresentation.SaveAs("Temporary", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoTrue);
temporaryPresentation.Close();

它对我有用。请让我知道这是否是预期的行为!