将powerpoint选定的幻灯片保存到桌面或所需位置

时间:2015-02-20 09:04:04

标签: c# powerpoint office-interop

我有以下代码,默认情况下将powerpoint保存到文档文件夹我想将其保存在桌面或提供选择文件夹以保存它的选项。

    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 ");
        }

    }

1 个答案:

答案 0 :(得分:0)

SaveAs方法不显示SaveAs对话框。您需要使用Application类的FileDialog属性,该属性返回一个FileDialog对象,该对象表示文件对话框的单个实例。例如:

Sub ShowSaveAsDialog()
    Dim dlgSaveAs As FileDialog
    Set dlgSaveAs = Application.FileDialog( _
        Type:=msoFileDialogSaveAs)
    dlgSaveAs.Show
End Sub

您可以使用任何.Net组件和类来在PowerPoint中实现所需的任务。例如,您可以使用BCL中的SaveAs对话框。有关详细信息,请参阅Powerpoint 2007 Save As Dialog