【问题标题】:DocumentOpen Word event is not working and how can I run the timer when the word file is openedDocumentOpen Word 事件不起作用,如何在打开 word 文件时运行计时器
【发布时间】:2021-01-28 12:18:07
【问题描述】:

打开文件时,我将其上传到服务器,但是打开文件时 Application_DocumentOpen 方法不起作用

如何在文件打开时每 30 秒运行一次上传方法

  void Application_DocumentOpen(Microsoft.Office.Interop.Word.Document Doc)
 {
            System.Timers.Timer timer = new System.Timers.Timer(30000);
            timer.Enabled = true;
            
            
            timer.Elapsed += (sender, e) => 
            DocumentEditingSendToServer(Doc.Application.ActiveDocument);
}

【问题讨论】:

    标签: c# vsto office-addins word-addins


    【解决方案1】:

    您需要创建一个 timer_tick 方法并每 30 秒从该方法上传一次。

    像这样:

    Timer Timer1 = new Timer();
    
    void Application_DocumentOpen(Microsoft.Office.Interop.Word.Document Doc)
     {
                InitializeTimer();
    }
    
    void InitializeTimer()
    {
         Timer1.Interval = 30000;
         Timer1.Tick += new EventHandler(Timer1_Tick);
    }
    
    private void Timer1_Tick (Object sender, EventArgs e)
    {
         DocumentEditingSendToServer(Doc.Application.ActiveDocument);
    }
    
    

    【讨论】:

      猜你喜欢
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      相关资源
      最近更新 更多