Ejemplo n.º 1
0
 /// <summary>
 /// Export the image from the tmpfile to the presentation with the supplied name
 /// </summary>
 /// <param name="presentationName">Name of the presentation to insert to</param>
 /// <param name="tmpFile">Filename of the image file to insert</param>
 /// <param name="imageSize">Size of the image</param>
 /// <param name="title">A string with the image title</param>
 /// <returns></returns>
 public static bool ExportToPresentation(string presentationName, string tmpFile, Size imageSize, string title)
 {
     using (IPowerpointApplication powerpointApplication = GetPowerpointApplication()) {
         if (powerpointApplication == null)
         {
             return(false);
         }
         using (IPresentations presentations = powerpointApplication.Presentations) {
             LOG.DebugFormat("Open Presentations: {0}", presentations.Count);
             for (int i = 1; i <= presentations.Count; i++)
             {
                 using (IPresentation presentation = presentations.item(i)) {
                     if (presentation == null)
                     {
                         continue;
                     }
                     if (!presentation.Name.StartsWith(presentationName))
                     {
                         continue;
                     }
                     try {
                         AddPictureToPresentation(presentation, tmpFile, imageSize, title);
                         return(true);
                     } catch (Exception e) {
                         LOG.Error(e);
                     }
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the captions of all the open powerpoint presentations
        /// </summary>
        /// <returns></returns>
        public static List <string> GetPowerpointPresentations()
        {
            List <string> foundPresentations = new List <string>();

            try {
                using (IPowerpointApplication powerpointApplication = GetPowerpointApplication()) {
                    if (powerpointApplication == null)
                    {
                        return(foundPresentations);
                    }

                    using (IPresentations presentations = powerpointApplication.Presentations) {
                        LOG.DebugFormat("Open Presentations: {0}", presentations.Count);
                        for (int i = 1; i <= presentations.Count; i++)
                        {
                            using (IPresentation presentation = presentations.item(i)) {
                                if (presentation == null)
                                {
                                    continue;
                                }
                                if (presentation.ReadOnly == MsoTriState.msoTrue)
                                {
                                    continue;
                                }
                                if (IsAfter2003())
                                {
                                    if (presentation.Final)
                                    {
                                        continue;
                                    }
                                }
                                foundPresentations.Add(presentation.Name);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                LOG.Warn("Problem retrieving word destinations, ignoring: ", ex);
            }
            foundPresentations.Sort();
            return(foundPresentations);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Insert a capture into a new presentation
        /// </summary>
        /// <param name="tmpFile"></param>
        /// <param name="imageSize"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static bool InsertIntoNewPresentation(string tmpFile, Size imageSize, string title)
        {
            bool isPictureAdded = false;

            using (IPowerpointApplication powerpointApplication = GetOrCreatePowerpointApplication()) {
                if (powerpointApplication != null)
                {
                    powerpointApplication.Visible = true;
                    using (IPresentations presentations = powerpointApplication.Presentations) {
                        using (IPresentation presentation = presentations.Add(MsoTriState.msoTrue)) {
                            try {
                                AddPictureToPresentation(presentation, tmpFile, imageSize, title);
                                isPictureAdded = true;
                            } catch (Exception e) {
                                LOG.Error(e);
                            }
                        }
                    }
                }
            }
            return(isPictureAdded);
        }