예제 #1
0
 /// <summary>
 /// Internal method for the insert
 /// </summary>
 /// <param name="wordApplication"></param>
 /// <param name="wordDocument"></param>
 /// <param name="tmpFile"></param>
 /// <param name="adress">link for the image</param>
 /// <param name="tooltip">tooltip of the image</param>
 /// <returns></returns>
 internal static bool InsertIntoExistingDocument(IWordApplication wordApplication, IWordDocument wordDocument, string tmpFile, string address, string tooltip)
 {
     // Make sure the selected document is active, otherwise the insert will be made in a different document!
     try {
         wordApplication.Activate();
     } catch {
     }
     if (wordApplication.Selection != null)
     {
         // Add Picture
         using (IInlineShape shape = AddPictureToSelection(wordApplication.Selection, tmpFile)) {
             if (!string.IsNullOrEmpty(address))
             {
                 object screentip = Type.Missing;
                 if (!string.IsNullOrEmpty(tooltip))
                 {
                     screentip = tooltip;
                 }
                 try {
                     wordDocument.Hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
                 } catch (Exception e) {
                     LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
                 }
             }
         }
         try {
             wordDocument.ActiveWindow.ActivePane.View.Zoom.Percentage = 100;
         } catch (Exception e) {
             if (e.InnerException != null)
             {
                 LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.InnerException.Message);
             }
             else
             {
                 LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message);
             }
         }
         try {
             wordApplication.Activate();
         } catch {}
         try {
             wordDocument.Activate();
         } catch {}
         try {
             wordDocument.ActiveWindow.Activate();
         } catch {}
         return(true);
     }
     return(false);
 }
예제 #2
0
 public static void InsertIntoNewDocument(string tmpFile, string address, string tooltip)
 {
     using (IWordApplication wordApplication = COMWrapper.GetOrCreateInstance <IWordApplication>()) {
         if (wordApplication != null)
         {
             wordApplication.Visible = true;
             wordApplication.Activate();
             // Create new Document
             object        template        = string.Empty;
             object        newTemplate     = false;
             object        documentType    = 0;
             object        documentVisible = true;
             IWordDocument wordDocument    = wordApplication.Documents.Add(ref template, ref newTemplate, ref documentType, ref documentVisible);
             // Add Picture
             using (IInlineShape shape = AddPictureToSelection(wordApplication.Selection, tmpFile)) {
                 if (!string.IsNullOrEmpty(address))
                 {
                     object screentip = Type.Missing;
                     if (!string.IsNullOrEmpty(tooltip))
                     {
                         screentip = tooltip;
                     }
                     try {
                         wordDocument.Hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
                     } catch (Exception e) {
                         LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
                     }
                 }
             }
             try {
                 wordApplication.Activate();
             } catch {
             }
             try {
                 wordDocument.Activate();
             } catch {
             }
             try {
                 wordDocument.ActiveWindow.Activate();
             } catch {
             }
         }
     }
 }
 public static void InsertIntoNewDocument(string tmpFile)
 {
     using (IWordApplication wordApplication = COMWrapper.GetOrCreateInstance <IWordApplication>()) {
         if (wordApplication != null)
         {
             wordApplication.Visible = true;
             wordApplication.Activate();
             // Create new Document
             object        template        = string.Empty;
             object        newTemplate     = false;
             object        documentType    = 0;
             object        documentVisible = true;
             IWordDocument wordDocument    = wordApplication.Documents.Add(ref template, ref newTemplate, ref documentType, ref documentVisible);
             // Add Picture
             AddPictureToSelection(wordApplication.Selection, tmpFile);
             wordDocument.Activate();
             wordDocument.ActiveWindow.Activate();
         }
     }
 }
예제 #4
0
 /// <summary>
 /// Internal method for the insert
 /// </summary>
 /// <param name="wordApplication"></param>
 /// <param name="wordDocument"></param>
 /// <param name="tmpFile"></param>
 /// <param name="adress">link for the image</param>
 /// <param name="tooltip">tooltip of the image</param>
 /// <returns></returns>
 internal static bool InsertIntoExistingDocument(IWordApplication wordApplication, IWordDocument wordDocument, string tmpFile, string address, string tooltip)
 {
     // Bug #1517: image will be inserted into that document, where the focus was last. It will not inserted into the chosen one.
     // Solution: Make sure the selected document is active, otherwise the insert will be made in a different document!
     try {
         wordDocument.Activate();
     } catch {
     }
     using (ISelection selection = wordApplication.Selection) {
         if (selection == null)
         {
             LOG.InfoFormat("No selection to insert {0} into found.", tmpFile);
             return(false);
         }
         // Add Picture
         using (IInlineShape shape = AddPictureToSelection(selection, tmpFile)) {
             if (!string.IsNullOrEmpty(address))
             {
                 object screentip = Type.Missing;
                 if (!string.IsNullOrEmpty(tooltip))
                 {
                     screentip = tooltip;
                 }
                 try {
                     using (IHyperlinks hyperlinks = wordDocument.Hyperlinks) {
                         hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
                     }
                 } catch (Exception e) {
                     LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
                 }
             }
         }
         try {
             using (IWordWindow activeWindow = wordDocument.ActiveWindow) {
                 activeWindow.Activate();
                 using (IPane activePane = activeWindow.ActivePane) {
                     using (IWordView view = activePane.View) {
                         view.Zoom.Percentage = 100;
                     }
                 }
             }
         } catch (Exception e) {
             if (e.InnerException != null)
             {
                 LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.InnerException.Message);
             }
             else
             {
                 LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message);
             }
         }
         try {
             wordApplication.Activate();
         } catch {
         }
         try {
             wordDocument.Activate();
         } catch {
         }
         return(true);
     }
 }
예제 #5
0
 public static void InsertIntoNewDocument(string tmpFile, string address, string tooltip)
 {
     using (IWordApplication wordApplication = GetOrCreateWordApplication()) {
         if (wordApplication == null)
         {
             return;
         }
         wordApplication.Visible = true;
         wordApplication.Activate();
         // Create new Document
         object template        = string.Empty;
         object newTemplate     = false;
         object documentType    = 0;
         object documentVisible = true;
         using (IDocuments documents = wordApplication.Documents) {
             using (IWordDocument wordDocument = documents.Add(ref template, ref newTemplate, ref documentType, ref documentVisible)) {
                 using (ISelection selection = wordApplication.Selection) {
                     // Add Picture
                     using (IInlineShape shape = AddPictureToSelection(selection, tmpFile)) {
                         if (!string.IsNullOrEmpty(address))
                         {
                             object screentip = Type.Missing;
                             if (!string.IsNullOrEmpty(tooltip))
                             {
                                 screentip = tooltip;
                             }
                             try {
                                 using (IHyperlinks hyperlinks = wordDocument.Hyperlinks) {
                                     hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
                                 }
                             } catch (Exception e) {
                                 Log.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
                             }
                         }
                     }
                 }
                 try {
                     wordDocument.Activate();
                 }
                 catch
                 {
                     // ignored
                 }
                 try {
                     using (var activeWindow = wordDocument.ActiveWindow)
                     {
                         activeWindow.Activate();
                         int hWnd = activeWindow.Hwnd;
                         if (hWnd > 0)
                         {
                             WindowDetails.ToForeground(new IntPtr(hWnd));
                         }
                     }
                 }
                 catch
                 {
                     // ignored
                 }
             }
         }
     }
 }
예제 #6
0
 /// <summary>
 ///     Internal method for the insert
 /// </summary>
 /// <param name="wordApplication"></param>
 /// <param name="wordDocument"></param>
 /// <param name="tmpFile"></param>
 /// <param name="address">link for the image</param>
 /// <param name="tooltip">tooltip of the image</param>
 /// <returns></returns>
 internal static bool InsertIntoExistingDocument(IWordApplication wordApplication, IWordDocument wordDocument, string tmpFile, string address, string tooltip)
 {
     // Bug #1517: image will be inserted into that document, where the focus was last. It will not inserted into the chosen one.
     // Solution: Make sure the selected document is active, otherwise the insert will be made in a different document!
     try
     {
         wordDocument.Activate();
     }
     catch
     {
         // ignored
     }
     using (var selection = wordApplication.Selection)
     {
         if (selection == null)
         {
             Log.Info().WriteLine("No selection to insert {0} into found.", tmpFile);
             return(false);
         }
         // Add Picture
         using (var shape = AddPictureToSelection(selection, tmpFile))
         {
             if (!string.IsNullOrEmpty(address))
             {
                 var screentip = Type.Missing;
                 if (!string.IsNullOrEmpty(tooltip))
                 {
                     screentip = tooltip;
                 }
                 try
                 {
                     using (var hyperlinks = wordDocument.Hyperlinks)
                     {
                         hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
                     }
                 }
                 catch (Exception e)
                 {
                     Log.Warn().WriteLine("Couldn't add hyperlink for image: {0}", e.Message);
                 }
             }
         }
         try
         {
             using (var activeWindow = wordDocument.ActiveWindow)
             {
                 activeWindow.Activate();
                 using (var activePane = activeWindow.ActivePane)
                 {
                     using (var view = activePane.View)
                     {
                         view.Zoom.Percentage = 100;
                     }
                 }
             }
         }
         catch (Exception e)
         {
             Log.Warn().WriteLine("Couldn't set zoom to 100, error: {0}", e.InnerException?.Message ?? e.Message);
         }
         try
         {
             wordApplication.Activate();
         }
         catch
         {
             // ignored
         }
         try
         {
             using (var activeWindow = wordDocument.ActiveWindow)
             {
                 activeWindow.Activate();
                 var hWnd = activeWindow.Hwnd;
                 if (hWnd > 0)
                 {
                     // TODO: Await?
                     InteropWindowFactory.CreateFor(new IntPtr(hWnd)).ToForegroundAsync();
                 }
             }
         }
         catch
         {
             // ignored
         }
         return(true);
     }
 }
예제 #7
0
		/// <summary>
		/// Internal method for the insert
		/// </summary>
		/// <param name="wordApplication"></param>
		/// <param name="wordDocument"></param>
		/// <param name="tmpFile"></param>
		/// <param name="adress">link for the image</param>
		/// <param name="tooltip">tooltip of the image</param>
		/// <returns></returns>
		internal static bool InsertIntoExistingDocument(IWordApplication wordApplication, IWordDocument wordDocument, string tmpFile, string address, string tooltip) {
			// Bug #1517: image will be inserted into that document, where the focus was last. It will not inserted into the chosen one.
			// Solution: Make sure the selected document is active, otherwise the insert will be made in a different document!
			try {
				wordDocument.Activate();
			} catch {
			}
			using (ISelection selection = wordApplication.Selection) {
				if (selection == null) {
					LOG.InfoFormat("No selection to insert {0} into found.", tmpFile);
					return false;
				}
				// Add Picture
				using (IInlineShape shape = AddPictureToSelection(selection, tmpFile)) {
					if (!string.IsNullOrEmpty(address)) {
						object screentip = Type.Missing;
						if (!string.IsNullOrEmpty(tooltip)) {
							screentip = tooltip;
						}
						try {
							using (IHyperlinks hyperlinks = wordDocument.Hyperlinks) {
								hyperlinks.Add(shape, screentip, Type.Missing, screentip, Type.Missing, Type.Missing);
							}
						} catch (Exception e) {
							LOG.WarnFormat("Couldn't add hyperlink for image: {0}", e.Message);
						}
					}
				}
				try {
					using (IWordWindow activeWindow = wordDocument.ActiveWindow) {
						activeWindow.Activate();
						using (IPane activePane = activeWindow.ActivePane) {
							using (IWordView view = activePane.View) {
								view.Zoom.Percentage = 100;
							}
						}
					}
				} catch (Exception e) {
					if (e.InnerException != null) {
						LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.InnerException.Message);
					} else {
						LOG.WarnFormat("Couldn't set zoom to 100, error: {0}", e.Message);
					}
				}
				try {
					wordApplication.Activate();
				} catch {
				}
				try {
					wordDocument.Activate();
				} catch {
				}
				return true;
			}
		}