Exemple #1
1
 private void MonthClosed()
 {
     Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
     Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
     Microsoft.Office.Core.MsoTriState otrue  = Microsoft.Office.Core.MsoTriState.msoTrue;
     pptApp.Visible = otrue;
     pptApp.Activate();
     Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
     Microsoft.Office.Interop.PowerPoint.Presentation  p  = ps.Open(@"F:\Mess Managment\Mess Notice\PPTFormatNotice\MonthClosed.pptx", ofalse, ofalse, otrue);
     System.Diagnostics.Debug.Print(p.Windows.Count.ToString());
 }
        public static void PptToHtmlFile(string PptFilePath)
        {
            //获得html文件名

            string htmlFileName = PptFilePath.Substring(0, PptFilePath.LastIndexOf(".")) + ".html";

            Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();

            Microsoft.Office.Interop.PowerPoint.Presentation pptFile = null;

            try
            {
                //打开一个ppt文件

                pptFile = ppt.Presentations.Open(PptFilePath, Microsoft.Office.Core.MsoTriState.msoTrue,

                                                 Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);

                //转换成html格式

                pptFile.SaveAs(htmlFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML,

                               Microsoft.Office.Core.MsoTriState.msoCTrue);
            }

            finally
            {
                if (pptFile != null)
                {
                    pptFile.Close();
                }
                ppt.Quit();
                GC.Collect();
            }
        }
Exemple #3
0
        /// <summary>把Word文件转换成为PDF格式文件</summary>   
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>
        public static bool PowerPointToHtml(string sourcePath, string targetPath)
        {
            bool result = false;

            try
            {
                //Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.;
                Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Core.MsoTriState m1 = new MsoTriState();
                Microsoft.Office.Core.MsoTriState m2 = new MsoTriState();
                Microsoft.Office.Core.MsoTriState m3 = new MsoTriState();
                Microsoft.Office.Interop.PowerPoint.Presentation pp = ppt.Presentations.Open(sourcePath, m1, m2, m3);
                pp.SaveAs(targetPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
                pp.Close();
                ppt.Quit();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                return(false);
            }
        }
Exemple #4
0
        private static void PrepareMediaFiles(Presentation pres, string tempPath)
        {
            string presFullName = pres.FullName;
            string presName     = pres.Name;
            string zipFullPath  = tempPath + tempZipName;

            // in case of embedded slides, we need to regulate the file name and full name
            RegulatePresentationName(pres, tempPath, ref presName, ref presFullName);
            if (IsEmptyFile(presFullName))
            {
                return;
            }

            try
            {
                // before we do everything, check if there's an undelete old zip file
                // due to some error
                OverwriteFileUsing(presFullName, zipFullPath);
                ExtractMediaFiles(zipFullPath, tempPath);
            }
            catch (Exception e)
            {
                ErrorDialogBox.ShowDialog(CommonText.ErrorPrepareMedia, "Files cannot be linked.", e);
            }
        }
Exemple #5
0
 protected override void Given()
 {
     this.slideManager       = new SlideManager();
     this.powerpointHandle   = new Microsoft.Office.Interop.PowerPoint.Application();
     this.presentationHandle = this.SUT.CreatePowerPointPresentation(this.powerpointHandle, false);
     this.initialSlideCount  = this.slideManager.GetSlideCount(this.presentationHandle);
 }
Exemple #6
0
    protected override void printWorker()
    {
        try
        {
            isPrinting       = true;
            officePowerPoint = new Microsoft.Office.Interop.PowerPoint.Application();
            officePowerPoint.DisplayAlerts = Microsoft.Office.Interop.PowerPoint.PpAlertLevel.ppAlertsNone;
            Microsoft.Office.Interop.PowerPoint.Presentation doc = null;
            doc = officePowerPoint.Presentations.Open(
                filename,
                Microsoft.Office.Core.MsoTriState.msoTrue,
                Microsoft.Office.Core.MsoTriState.msoFalse,
                Microsoft.Office.Core.MsoTriState.msoFalse);
            doc.PrintOptions.ActivePrinter     = printer;
            doc.PrintOptions.PrintInBackground = Microsoft.Office.Core.MsoTriState.msoFalse;
            doc.PrintOptions.OutputType        = Microsoft.Office.Interop.PowerPoint.PpPrintOutputType.ppPrintOutputSlides;
            doc.PrintOut();
            System.Threading.Thread.Sleep(500);
            doc.Close();
            Marshal.FinalReleaseComObject(doc);
            doc           = null;
            workerPrintOk = true;
            isPrinting    = true;
        }
        catch (System.Exception ex)
        {
            isPrinting = false;

            Logging.Log("Unable to print PowerPoint file " + filename + ". Exception: " + ex.Message, Logging.LogLevel.Error);
            workerPrintOk = false;
        }
    }
Exemple #7
0
        protected override void Given()
        {
            this.powerpointHandle   = new Microsoft.Office.Interop.PowerPoint.Application();
            this.slideManager       = new SlideManager();
            this.presentationHandle = this.SUT.CreatePowerPointPresentation(this.powerpointHandle, false);

            // Add some slides to the presentation
            this.slideHandle = this.slideManager.AddSlideToEnd(this.presentationHandle);
            this.slideHandle = this.slideManager.AddSlideToEnd(this.presentationHandle);
            this.slideHandle = this.slideManager.AddSlideToEnd(this.presentationHandle);

            // Add some shapes to slides
            this.shapesHandler.DrawShape(
                this.presentationHandle.Slides[1],
                MsoAutoShapeType.msoShapeRectangle,
                100f,
                100f,
                100f,
                100f);

            this.shapesHandler.DrawShape(
                this.presentationHandle.Slides[2],
                MsoAutoShapeType.msoShapeRectangle,
                100f,
                100f,
                100f,
                100f);
        }
Exemple #8
0
        /// <summary>
        /// PPT转成Html
        /// </summary>
        /// <param name="physicalPath">文件物理路径 绝对路径</param>
        /// <param name="serverPath">文件服务器路径 相对路径</param>
        /// <returns></returns>
        public static OfficeResult PPTToHtml(string physicalPath, string serverPath)
        {
            OfficeResult res = new OfficeResult();

            try
            {
                //-------------------------------------------------
                Microsoft.Office.Interop.PowerPoint.Application  ppApp   = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(physicalPath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                string htmlName   = Path.GetFileNameWithoutExtension(physicalPath) + ".html";
                string outputFile = Path.GetDirectoryName(physicalPath) + "\\" + htmlName;
                prsPres.SaveAs(outputFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
                prsPres.Close();
                ppApp.Quit();
                //---------------------------------------------------------------
                //return Path.GetDirectoryName(System.Web.HttpContext.Current.Server.UrlDecode(url)) + "\\" + htmlName;
                string previewFile = Path.GetDirectoryName(serverPath) + "\\" + htmlName;
                res.code    = 1;
                res.message = previewFile;
                return(res);
            }
            catch (Exception ex)
            {
                res.code    = 0;
                res.message = ex.Message;
                return(res);
            }
        }
 public Presentation(Size paperSize)
 {
     _powerPoint   = new Microsoft.Office.Interop.PowerPoint.Application();
     _presentation = _powerPoint.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
     _presentation.PageSetup.SlideHeight = paperSize.Height;
     _presentation.PageSetup.SlideWidth  = paperSize.Width;
 }
Exemple #10
0
        protected override void Given()
        {
            var pptApplication = this.applicationHandler.CreatePowerPointApplication();

            this.slideManager = new SlideManager();
            this.presentation = this.presentationHandler.CreatePowerPointPresentation(pptApplication, false);
        }
Exemple #11
0
        private void btnConvertAll_Click(object sender, EventArgs e)
        {
            progressBar1.Visible = true;
            progressBar1.Maximum = listBoxFiles.Items.Count;
            progressBar1.Step    = 1;
            Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
            foreach (object logListItem in listBoxFiles.Items)
            {
                progressBar1.PerformStep();
                this.Refresh();

                string strLogName      = logListItem.ToString();
                string strFullFilePath = textBoxFolder.Text + "\\" + strLogName;

                if (File.Exists(strFullFilePath + ".ppt"))
                {
                    Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApp.Presentations.Open(strFullFilePath + ".ppt", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                    pptPresentation.SaveAs(strFullFilePath + ".pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPicturePresentation);
                    pptPresentation.Close();
                }
            }
            pptApp.Quit();
            progressBar1.Visible = false;
        }
        /// <summary>
        ///     The convert to pptx.
        /// </summary>
        /// <param name="fullPath">The full path.</param>
        /// <param name="targetLanguage">The target language.</param>
        /// <returns>
        ///     The System.String.
        /// </returns>
        private static string ConvertToPptx(string fullPath, string targetLanguage)
        {
            LoggingManager.LogMessage("Converting the document " + fullPath + " from ppt to pptx.");

            object file2 = GetOutputDocumentFullName(fullPath, targetLanguage);

            Microsoft.Office.Interop.PowerPoint.Application powerPointApp =
                new Microsoft.Office.Interop.PowerPoint.Application();

            try
            {
                Microsoft.Office.Interop.PowerPoint.Presentation presentation =
                    powerPointApp.Presentations.Open(
                        fullPath,
                        MsoTriState.msoFalse,
                        MsoTriState.msoFalse,
                        MsoTriState.msoFalse);

                presentation.SaveAs(
                    file2.ToString(),
                    Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
                    MsoTriState.msoTriStateMixed);
                presentation.Close();
            }
            finally
            {
                powerPointApp.Quit();
            }

            LoggingManager.LogMessage("Converted the document " + fullPath + " from ppt to pptx.");
            return(file2.ToString());
        }
Exemple #13
0
        public static void saveSlides(Microsoft.Office.Interop.PowerPoint.Presentation presentation)
        {
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            //string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string filePath = desktopPath + "\\Slides.pptx";


            // Microsoft.Office.Interop.PowerPoint.FileConverter fc = new Microsoft.Office.Interop.PowerPoint.FileConverter();
            // if (fc.CanSave) { }
            //https://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog(v=vs.110).aspx

            //Browse Files
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.InitialDirectory = desktopPath + "\\Scano";
            dlg.DefaultExt       = ".pptx";
            dlg.Filter           = "PPTX Files (*.pptx)|*.pptx";
            Nullable <bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                filePath = dlg.FileName;
                //textBox1.Text = filename;
            }
            else
            {
                System.Console.WriteLine("Couldn't show the dialog.");
            }

            presentation.SaveAs(filePath,
                                Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation,
                                Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
            System.Console.WriteLine("PowerPoint application saved in {0}.", filePath);
        }
Exemple #14
0
        /// <summary>
        /// Reads PPT and PPTX file types and extracts the words in each file
        /// Requires: The file path is in ppt or pptx format only
        /// </summary>
        /// <param name="filenameWithPath">path of PPT and PPTX document including filename</param>
        /// <exception cref="PlatformNotSupportedException">Thrown when the file to read is not of supported
        /// presentation format. </exception>
        /// <returns>
        /// A Dictionary where the Key contains the filename and the Value contains the entire wordlist
        /// </returns>
        private static Dictionary <string, List <string> > readPPTFiles(string filenameWithPath)
        {
            Contract.Requires <PlatformNotSupportedException>(System.IO.Path.GetExtension(filenameWithPath).Equals(".ppt") ||
                                                              System.IO.Path.GetExtension(filenameWithPath).Equals(".pptx"));

            List <string> result = new List <string>();
            Dictionary <string, List <string> > listresult = new Dictionary <string, List <string> >();

            Microsoft.Office.Interop.PowerPoint.Application   PowerPoint_App      = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;
            Microsoft.Office.Interop.PowerPoint.Presentation  presentation        = multi_presentations.Open(filenameWithPath);
            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                foreach (var item in presentation.Slides[i + 1].Shapes)
                {
                    var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;
                    if (shape.HasTextFrame == MsoTriState.msoTrue)
                    {
                        if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                        {
                            var    textRange = shape.TextFrame.TextRange;
                            string text      = textRange.Text.ToLower().Trim().ToString();
                            result.AddRange(text.Split(new char[] { ' ', '\n', '\t', '\r' }));
                        }
                    }
                }
            }
            PowerPoint_App.Quit();
            listresult.Add(filenameWithPath, result);
            return(listresult);
        }
Exemple #15
0
 protected override void Given()
 {
     this.powerpointHandle   = new Microsoft.Office.Interop.PowerPoint.Application();
     this.slideManager       = new SlideManager();
     this.presentationHandle = this.SUT.CreatePowerPointPresentation(this.powerpointHandle, false);
     this.slideHandle        = this.slideManager.AddSlideToEnd(this.presentationHandle);
     this.shapesHandler      = new ShapesManager();
 }
 public void Close()
 {
     if (presentation != null)
     {
         presentation.Close();
         slides       = null;
         presentation = null;
     }
 }
Exemple #17
0
 public void Compare(string orginal, string target)
 {
     Microsoft.Office.Interop.PowerPoint.Application powerPoint = new Microsoft.Office.Interop.PowerPoint.Application {
         Visible = MsoTriState.msoCTrue
     };
     Microsoft.Office.Interop.PowerPoint.Presentation presentation = powerPoint.Presentations.Open(orginal);
     presentation.Merge(target);
     powerPoint.ActivePresentation.Saved = MsoTriState.msoCTrue;
 }
Exemple #18
0
 protected override void Given()
 {
     this.slideManager       = new SlideManager();
     this.powerpointHandle   = new Microsoft.Office.Interop.PowerPoint.Application();
     this.presentationHandle = this.SUT.CreatePowerPointPresentation(this.powerpointHandle, false);
     this.slideHandle        = this.slideManager.AddSlideToEnd(this.presentationHandle);
     this.shapesHandler      = new Shapes();
     this.returnedShape      = this.shapesHandler.AddTextBoxToSlide(this.slideHandle, MsoTextOrientation.msoTextOrientationHorizontal, 100f, 100f, 100f, 100f);
 }
 public void Create(string strTemplate)
 {
     if (powerpoint == null)
     {
         OpenPowerPoint();
     }
     //Create a new presentation based on a template.
     presentation = presentationSet.Open(strTemplate, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
     slides       = presentation.Slides;
 }
 public void Initialised(object context)
 {
     presentation = (Microsoft.Office.Interop.PowerPoint.Presentation)context;
     if (presentation == null)
     {
         return;
     }
     application = presentation.Application;
     application.PresentationNewSlide += ApplicationOnPresentationNewSlide;
 }
        /// <summary>
           /// ppt convert to html
           /// </summary>
           /// <param name="path">要转换的文档的路径</param>
           /// <param name="savePath">转换成的html的保存路径</param>
           /// <param name="wordFileName">转换后html文件的名字</param>
        public static void PPTToHtml(string path, string savePath, string wordFileName)
        {
            Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
            string strSourceFile      = path;
            string strDestinationFile = savePath + wordFileName + ".html";

            Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(strSourceFile, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
            prsPres.Close();
            ppApp.Quit();
        }
Exemple #22
0
 private void bunifuThinButton23_Click(object sender, EventArgs e)
 {
     Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
     Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
     Microsoft.Office.Core.MsoTriState otrue  = Microsoft.Office.Core.MsoTriState.msoTrue;
     pptApp.Visible = otrue;
     pptApp.Activate();
     Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
     Microsoft.Office.Interop.PowerPoint.Presentation  p  = ps.Open(@"F:\Mess Managment\Mess Notice\PPTFormatNotice\PenaltyMeal.pptx", ofalse, ofalse, otrue);
     System.Diagnostics.Debug.Print(p.Windows.Count.ToString());
 }
Exemple #23
0
        private Boolean unlockPowerPoint(String r_password, String w_password)
        {
            Boolean NOPASS = true;

            /////////////////////////////////////////////////////
            // PwerPoint解錠
            /////////////////////////////////////////////////////
            if (avaPoawrPoint)
            {
                try {
                    pptPre = pptPres.Open(dataGridView1.Rows[0].Cells[3].Value.ToString() + ":: :: ",
                                          MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
                } catch {
                    NOPASS = false;
                }

                if (NOPASS)
                {
                    // パスワードがかかっていない
                    label2.Text = WindowsFormsApplication1.Properties.Resources.powerpoint2;
                    // "This presentation is not applied password.";
                    return(false);
                }
                else
                {
                    String rp = (r_password.Length == 0) ? ":: " : "::" + r_password;
                    String wp = (w_password.Length == 0) ? ":: " : "::" + w_password;

                    try {
                        pptPre = pptPres.Open(dataGridView1.Rows[0].Cells[3].Value.ToString() + rp + wp,
                                              Microsoft.Office.Core.MsoTriState.msoFalse,
                                              Microsoft.Office.Core.MsoTriState.msoFalse,
                                              Microsoft.Office.Core.MsoTriState.msoFalse);
                    } catch {
                        label2.Text = WindowsFormsApplication1.Properties.Resources.message2;
                        //"Password is incorrect.";
                        return(false);
                    }

                    pptPre.Password      = null;
                    pptPre.WritePassword = null;
                    try {
                        pptPre.Save();
                    } catch (Exception eX) {
                        label2.Text = WindowsFormsApplication1.Properties.Resources.error1 + eX.Message;
                        // "Saving failed." + eX.Message;
                        return(false);
                    }
                    pptPre.Close();
                }
            }
            return(true);
        }
Exemple #24
0
 private void button1_Click(object sender, EventArgs e)
 {
     Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
     Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
     Microsoft.Office.Core.MsoTriState otrue  = Microsoft.Office.Core.MsoTriState.msoTrue;
     pptApp.Visible = otrue;
     pptApp.Activate();
     Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
     Microsoft.Office.Interop.PowerPoint.Presentation  p  = ps.Open(@"F:\Mess Managment\PersonalCostV.1.1.00V.pptx", ofalse, ofalse, otrue);
     System.Diagnostics.Debug.Print(p.Windows.Count.ToString());
     MessageBox.Show(pptApp.ActiveWindow.Caption);
 }
Exemple #25
0
        private void ConvertFile(string strFilePath)
        {
            if (File.Exists(strFilePath + ".ppt"))
            {
                Microsoft.Office.Interop.PowerPoint.Application  pptApp          = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApp.Presentations.Open(strFilePath + ".ppt", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                pptPresentation.SaveAs(strFilePath + ".pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPicturePresentation);
                pptPresentation.Close();

                pptApp.Quit();
            }
        }
        public static void close()
        {
            if (Ppt != null)
            {
                Ppt.Close();
                Ppt = null;
            }

            if (App != null)
            {
                App.Quit();
                App = null;
            }
        }
Exemple #27
0
 public static bool CreatePowerPoint()
 {
     try
     {   //create powerpoint
         ppPresens = ppApp.Presentations;
         objPres   = ppPresens.Add();
         objSlides = objPres.Slides;
     }
     catch (Exception e)
     {
         Console.WriteLine("Creating PowerPoint Failed: " + fileName + "\n" + e.Message);
     }
     return(result);
 }
Exemple #28
0
        public override bool PPT2HTML(string sourcePath, string targetPath, string targetRelativeDirectory)
        {
            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.Application  pptApp       = null;
            Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
            try
            {
                if (!sourcePath.EndsWith(".ppt") && !sourcePath.EndsWith(".pptx"))
                {
                    return(false);
                }

                if (File.Exists(targetPath))
                {
                    File.Delete(targetPath);
                }
                object target = targetPath;
                pptApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                Microsoft.Office.Interop.PowerPoint.Presentations presentations = pptApp.Presentations;

                presentation = presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                presentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
            }
            catch (Exception e)
            {
                Log.LogInfo("ppt转换html:", e);
                return(false);
            }
            finally
            {
                if (presentation != null)
                {
                    presentation.Close();
                    presentation = null;
                }
                if (pptApp != null)
                {
                    pptApp.Quit();
                    pptApp = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            pptHelper(targetPath, targetRelativeDirectory);

            return(true);
        }
        static void Main(string[] args)
        {
            string strPath =
                System.AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/");

            // Instantiate Object
            APServer.Server server = new APServer.Server();

            // Path and filename of output
            server.NewDocumentName = "Server.PowerPointPrinting.pdf";
            server.OutputDirectory = strPath;

            // Start the print job
            ServerDK.Results.ServerResult result = server.BeginPrintToPDF();
            if (result.ServerStatus == ServerDK.Results.ServerStatus.Success)
            {
                // Automate PowerPoint to print a document to activePDF Server
                // NOTE: You must add the 'Microsoft PowerPoint
                // <<version number>> Object Library' COM object as a reference
                // to your .NET application to access the PowerPoint Object.
                Microsoft.Office.Interop.PowerPoint._Application oPPT =
                    new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation oPRES =
                    oPPT.Presentations.Open(
                        $"{strPath}Server.PowerPoint.Input.pptx",
                        Microsoft.Office.Core.MsoTriState.msoTrue,
                        Microsoft.Office.Core.MsoTriState.msoFalse,
                        Microsoft.Office.Core.MsoTriState.msoFalse);
                Microsoft.Office.Interop.PowerPoint.PrintOptions objOptions =
                    oPRES.PrintOptions;
                objOptions.ActivePrinter     = server.NewPrinterName;
                objOptions.PrintInBackground = 0;
                oPRES.PrintOut(1, 9999, "", 1, 0);
                oPRES.Saved = Microsoft.Office.Core.MsoTriState.msoTrue;
                oPRES.Close();
                oPPT.Quit();

                // Wait(seconds) for job to complete
                result = server.EndPrintToPDF(waitTime: 30);
            }

            // Output result
            WriteResult(result);

            // Process Complete
            Console.WriteLine("Done!");
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
 protected override void OnStart(CustomForm Sender)
 {
     Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
     Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
     Microsoft.Office.Core.MsoTriState otrue  = Microsoft.Office.Core.MsoTriState.msoTrue;
     pptApp.Visible = otrue;
     pptApp.Activate();
     Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
     opApp = new Microsoft.Office.Interop.PowerPoint.Application();
     opApp.SlideShowNextSlide += OpApp_SlideShowNextSlide;
     ppPresentation            = ps.Open(@"c:\a.pptx", ofalse, ofalse, otrue);
     settings               = ppPresentation.SlideShowSettings;
     settings.RangeType     = Microsoft.Office.Interop.PowerPoint.PpSlideShowRangeType.ppShowSlideRange;
     settings.StartingSlide = StartingSlide;
     settings.Run();
 }
        public override void Convert(string src, string dest, out string msg)
        {
            msg = null;
            try
            {
                if (string.IsNullOrEmpty(src))
                {
                    msg = "源文件不能为空";
                    return;
                }
                var contentType = MimeTypes.GetContentType(src);
                if (contentType != "application/mspowerpoint")
                {
                    msg = "源文件应为powerpoint文件";
                    return;
                }
                if (string.IsNullOrEmpty(dest))
                {
                    msg = "目标路径不能为空";
                    return;
                }
                if (!File.Exists(src))
                {
                    msg = "文件不存在";
                    return;
                }

                if (IsPasswordProtected(src))
                {
                    msg = "存在密码";
                    return;
                }

                app           = new Microsoft.Office.Interop.PowerPoint.Application();
                presentations = app.Presentations;
                presentation  = presentations.Open(src.ToString(), Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                presentation.ExportAsFixedFormat(dest.ToString(), Microsoft.Office.Interop.PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF);
                // presentation.ExportAsFixedFormat(outputFile, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentScreen, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoFalse, null, PowerPoint.PpPrintRangeType.ppPrintAll, "", false, false, false, false, false, null);
            }
            catch (Exception e)
            {
                release();
                throw new ConvertException(e.Message);
            }
            release();
        }
        public static void LoadPowerPoint(String filePath)
        {
            if(filePath == null || filePath == ""){
                return;
            }
            FilePath = filePath;
            App = new Microsoft.Office.Interop.PowerPoint.Application();
            App.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;

            Ppt = App.Presentations.Open(filePath,
                Microsoft.Office.Core.MsoTriState.msoTrue,
                Microsoft.Office.Core.MsoTriState.msoTrue,
                Microsoft.Office.Core.MsoTriState.msoTrue);

            slideIndex = new int[Ppt.Slides.Count];
            for (int i = 0; i < slideIndex.Length; i++)
            {
                slideIndex[i] = i + 1;
            }
        }
Exemple #33
-1
        public PowerPointControl()
        {
            // OpenFileDialog Instanz erzeugen
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Dateiendungs-Filter setzen
            dlg.DefaultExt = ".pptx";
            dlg.Filter = "Powerpoint|*.ppt;*.pptx|All files|*.*";

            // OpenFileDialog anzeigen
            Nullable<bool> result = dlg.ShowDialog();

            // PowerPoint Instanz erzeugen
            oPPT = new Microsoft.Office.Interop.PowerPoint.Application();
            // PowerPoint anzeigen
            oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
            objPresSet = oPPT.Presentations;

            // Wenn der Benutzer im OpenFileDialog eine Datei ausgewählt + auf OK geklickt hat
            if (result == true)
            {
                // Ausgewählte Datei (Präsentation) öffnen
                objPres = objPresSet.Open(dlg.FileName, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);

                // Präsentationsansicht öffnen
                objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse;
                System.Diagnostics.Debug.WriteLine(objPres.SlideShowSettings.ShowWithAnimation);
                objPres.SlideShowSettings.Run();

                oSlideShowView = objPres.SlideShowWindow.View;
            }
        }
Exemple #34
-1
        private void OpenPPT()
        {
            //Create an instance of PowerPoint.
            oPPT = new Microsoft.Office.Interop.PowerPoint.Application();
            // Show PowerPoint to the user.
            oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
            objPresSet = oPPT.Presentations;



                string pptFilePath = "C:\\Users\\bastisusewind\\Desktop\\Test.pptx";
                //open the presentation
                objPres = objPresSet.Open(pptFilePath, MsoTriState.msoFalse,
                MsoTriState.msoTrue, MsoTriState.msoTrue);

                objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse;
                System.Diagnostics.Debug.WriteLine(objPres.SlideShowSettings.ShowWithAnimation);
                objPres.SlideShowSettings.Run();

                oSlideShowView = objPres.SlideShowWindow.View;

        }