2016-05-18 9 views
0

NetOffice v1.7.3でWord Addin Projectを作成しました。NetOffice Word Addinで新しい文書イベントを聴く方法

2つのイベント(OnStartupCompleteとOnDisconnection)が接続されています。

<!-- language: c# --> 
public class Addin : Word.Tools.COMAddin 
{ 
     public Addin() 
     { 
      this.OnStartupComplete += new OnStartupCompleteEventHandler(Addin_OnStartupComplete); 
      this.OnDisconnection += new OnDisconnectionEventHandler(Addin_OnDisconnection); 
     } 
} 

新しいドキュメントイベントを受信し、ドキュメントイベントを保存し、ドキュメントイベントを閉じることができますか?

このコードはネット上に見つかりましたが、NetOfficeでどのように行うのか練習できません。アドバンス
よろしくダットで

<!-- language: c# --> 
private void ThisAddIn_Startup(object sender, System.EventArgs e) 
{ 
    Microsoft.Office.Interop.Word.ApplicationEvents2_Event wdEvents2 = (Microsoft.Office.Interop.Word.ApplicationEvents2_Event) this.Application; 
    wdEvents2.NewDocument += new Word.ApplicationEvents2_NewDocumentEventHandler(wdEvents2_NewDocument); 
} 

void wdEvents2_NewDocument(Word.Document Doc) 
{ 
    MessageBox.Show("New Document Fires.", "New Document", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
} 

感謝。

答えて

0
private void Addin_OnStartupComplete(ref Array custom) 
{ 
    Debug.WriteLine(string.Format("Word Addin started in Word Version {0}",Application.Version)); 
    this.Application.NewDocumentEvent += Application_NewDocumentEvent; 
    this.Application.DocumentBeforeCloseEvent += Application_DocumentBeforeCloseEvent; 
    this.Application.DocumentBeforeSaveEvent += Application_DocumentBeforeSaveEvent; 
    this.Application.DocumentBeforePrintEvent += Application_DocumentBeforePrintEvent; 
} 

private void Application_DocumentBeforePrintEvent(Word.Document Doc, ref bool Cancel) 
{ 
    if (Cancel == false) 
    { 
     Debug.WriteLine(string.Format("{0} Addin Document {1} is printing", AppName, Doc.Name)); 
    } 
} 

private void Application_DocumentBeforeSaveEvent(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel) 
{ 
    if (Cancel == false) 
    { 
     Debug.WriteLine(string.Format("{0} Addin Document {1} is saving", AppName, Doc.Name)); 
    } 
} 

private void Application_DocumentBeforeCloseEvent(Word.Document Doc, ref bool Cancel) 
{ 
    if (Cancel == false) 
    { 
     Debug.WriteLine(string.Format("{0} Addin Document is closing.. {1}", AppName, Doc.Name)); 
    } 
} 
関連する問題