Beispiel #1
0
        private static string SaveAsPptx(string pptPathIn)
        {
            Microsoft.Office.Interop.PowerPoint.Application presentationApp = new Microsoft.Office.Interop.PowerPoint.Application();
            string pptxPathOut = null;

            try
            {
                string pptDir          = Path.GetDirectoryName(pptPathIn);
                string pptFileNameOnly = Path.GetFileNameWithoutExtension(pptPathIn);
                pptxPathOut             = Path.Combine(pptDir, pptFileNameOnly + ".pptx");
                presentationApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;

                Microsoft.Office.Interop.PowerPoint.Presentations presentations = presentationApp.Presentations;

                Microsoft.Office.Core.MsoTriState readOnly   = Microsoft.Office.Core.MsoTriState.msoFalse;
                Microsoft.Office.Core.MsoTriState untitled   = Microsoft.Office.Core.MsoTriState.msoFalse;
                Microsoft.Office.Core.MsoTriState withWindow = Microsoft.Office.Core.MsoTriState.msoFalse;

                Debug.Print("Opening ppt file {0} ...", pptPathIn);
                Microsoft.Office.Interop.PowerPoint.Presentation presentation = presentations.Open(pptPathIn, readOnly, untitled, withWindow);

                Debug.Print("Starting creation of pptx from ppt {0}", pptPathIn);
                presentation.SaveCopyAs(pptxPathOut, PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation, Microsoft.Office.Core.MsoTriState.msoFalse);
                Debug.Print("Successfully created pptx {0} from ppt {1}", pptxPathOut, pptPathIn);
            }
            catch (Exception e)
            {
                Debug.Print("Error during creating pptx from ppt " + pptPathIn, e);
            }
            finally
            {
                presentationApp.Quit();
            }

            return(pptxPathOut);
        }