【问题标题】:VSTO Word, Excel, PowerPoind detect Save and AutoSaveVSTO Word、Excel、PowerPoind 检测保存和自动保存
【发布时间】:2022-10-25 03:57:20
【问题描述】:

如何在 Office AddIn for Excel、Word、PowerPoint 事件中检测和区分:

  • 用户保存(Ctrl+S,软盘图标)
  • 自动保存
  • 保存新文档(先保存,另存为)
  • 文档已关闭

这三个应用程序都没有 AfterSave、AfterAutoSave 和 AfterUiSave 事件。

Word 和 Excel 甚至没有 DocumentClose 事件。

【问题讨论】:

    标签: vsto office-interop office-addins excel-addins powerpoint-addins


    【解决方案1】:

    我几乎解决了所有问题,我想分享我的 sn-ps。

    支持 AfterSave、AfterAutoSave 一个 AfterUiSave for Word 我在这里找到并“按原样”使用:https://theofficecontext.com/2011/05/05/word-aftersave-event/

    我在这里上传的更改 PowerPoint: https://gist.github.com/VitekBed/fc2a24f67af3cf81784ba98f0bbc183f

    Excel 的更改还包含 WorkbookClosed 的扩展名(最初来自 https://gist.github.com/jmangelo/301884)上传到这里:https://gist.github.com/VitekBed/a2e1582ab9500e9513b39b85c53a6e89

    Excel ThisAddIn.cs 中的示例 ThisAddIn.AppInit()

    WorkbookClosedMonitor wcm = new WorkbookClosedMonitor(Application);
    wcm.WorkbookClosed += new EventHandler<WorkbookClosedEventArgs>(wcm_WorkbookClosed);
    
    WordSaveHandler wsh = new WordSaveHandler(Application);
    wsh.AfterAutoSaveEvent += new WordSaveHandler.AfterSaveDelegate(wsh_AfterAutoSaveEvent);
    wsh.AfterSaveEvent += new WordSaveHandler.AfterSaveDelegate(wsh_AfterSaveEvent);
    wsh.AfterUiSaveEvent += new WordSaveHandler.AfterSaveDelegate(wsh_AfterUiSaveEvent);
    

    唯一未解决的问题是 AfetrUiSave for PowerPoint,但它对我来说并不重要。对我来说至关重要的是检测自动保存并为保存和自动保存采取不同的行动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多