/// <summary> /// Call this to get the running powerpoint application, or create a new instance /// </summary> /// <returns>IPowerpointApplication</returns> private static IPowerpointApplication GetOrCreatePowerpointApplication() { IPowerpointApplication powerpointApplication = COMWrapper.GetOrCreateInstance <IPowerpointApplication>(); InitializeVariables(powerpointApplication); return(powerpointApplication); }
/// <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); }
/// <summary> /// Get the captions of all the open powerpoint presentations /// </summary> /// <returns></returns> public static System.Collections.Generic.List <string> GetPowerpointPresentations() { System.Collections.Generic.List <string> presentations = new System.Collections.Generic.List <string>(); try { using (IPowerpointApplication powerpointApplication = COMWrapper.GetInstance <IPowerpointApplication>()) { if (powerpointApplication != null) { if (version == null) { version = powerpointApplication.Version; } LOG.DebugFormat("Open Presentations: {0}", powerpointApplication.Presentations.Count); for (int i = 1; i <= powerpointApplication.Presentations.Count; i++) { IPresentation presentation = powerpointApplication.Presentations.item(i); if (presentation != null && presentation.ReadOnly != MsoTriState.msoTrue) { if (isAfter2003()) { if (presentation.Final) { continue; } } presentations.Add(presentation.Name); } } } } } catch (Exception ex) { LOG.Warn("Problem retrieving word destinations, ignoring: ", ex); } return(presentations); }
private static void InsertIntoNewPresentation(IPowerpointApplication powerpointApplication, string tmpFile, Image image, ICaptureDetails captureDetails) { LOG.Debug("No Presentation, creating a new Presentation"); IPresentation presentation = powerpointApplication.Presentations.Add(MsoTriState.msoTrue); AddPictureToPresentation(presentation, tmpFile, image, captureDetails); }
public static void InsertIntoNewPresentation(string tmpFile, Size imageSize, string title) { using (IPowerpointApplication powerpointApplication = COMWrapper.GetOrCreateInstance <IPowerpointApplication>()) { if (powerpointApplication != null) { powerpointApplication.Visible = true; IPresentation presentation = powerpointApplication.Presentations.Add(MsoTriState.msoTrue); AddPictureToPresentation(presentation, tmpFile, imageSize, title); presentation.Application.Activate(); } } }
/// <summary> /// Initialize static outlook variables like version and currentuser /// </summary> /// <param name="powerpointApplication">IPowerpointApplication</param> private static void InitializeVariables(IPowerpointApplication powerpointApplication) { if (powerpointApplication == null || _powerpointVersion != null) { return; } try { _powerpointVersion = new Version(powerpointApplication.Version); LOG.InfoFormat("Using Powerpoint {0}", _powerpointVersion); } catch (Exception exVersion) { LOG.Error(exVersion); LOG.Warn("Assuming Powerpoint version 1997."); _powerpointVersion = new Version((int)OfficeVersion.OFFICE_97, 0, 0, 0); } }
/// <summary> /// Initialize static outlook variables like version and currentuser /// </summary> /// <param name="powerpointApplication">IPowerpointApplication</param> private static void InitializeVariables(IPowerpointApplication powerpointApplication) { if (powerpointApplication == null || _powerpointVersion != null) { return; } try { _powerpointVersion = new Version(powerpointApplication.Version); Log.Info().WriteLine("Using Powerpoint {0}", _powerpointVersion); } catch (Exception exVersion) { Log.Error().WriteLine(exVersion); Log.Warn().WriteLine("Assuming Powerpoint version 1997."); _powerpointVersion = new Version((int)OfficeVersions.Office97, 0, 0, 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); }
public static bool InsertIntoNewPresentation(string tmpFile, Size imageSize, string title) { bool isPictureAdded = false; using (IPowerpointApplication powerpointApplication = COMWrapper.GetOrCreateInstance <IPowerpointApplication>()) { if (powerpointApplication != null) { powerpointApplication.Visible = true; IPresentation presentation = powerpointApplication.Presentations.Add(MsoTriState.msoTrue); try { AddPictureToPresentation(presentation, tmpFile, imageSize, title); isPictureAdded = true; presentation.Application.Activate(); } catch (Exception e) { LOG.Error(e); } } } return(isPictureAdded); }
public static void ExportToPowerpoint(string tmpFile, Image image, ICaptureDetails captureDetails) { using (IPowerpointApplication powerpointApplication = PowerpointApplication()) { if (powerpointApplication != null) { LOG.DebugFormat("Open Presentations: {0}", powerpointApplication.Presentations.Count); if (powerpointApplication.Presentations.Count > 0) { if (powerpointApplication.ActivePresentation != null) { LOG.Debug("Presentation found!"); AddPictureToPresentation(powerpointApplication.ActivePresentation, tmpFile, image, captureDetails); } } else { InsertIntoNewPresentation(powerpointApplication, tmpFile, image, captureDetails); } powerpointApplication.Visible = true; } } }
/// <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 = COMWrapper.GetInstance <IPowerpointApplication>()) { if (powerpointApplication != null) { LOG.DebugFormat("Open Presentations: {0}", powerpointApplication.Presentations.Count); for (int i = 1; i <= powerpointApplication.Presentations.Count; i++) { IPresentation presentation = powerpointApplication.Presentations.item(i); if (presentation != null && presentation.Name.StartsWith(presentationName)) { try { AddPictureToPresentation(presentation, tmpFile, imageSize, title); return(true); } catch (Exception e) { LOG.Error(e); } } } } } return(false); }