如何为Word文档插件创建AfterSave事件

3

我是一名新手插件编程,我的需求是想从C#中为Word文档添加AfterSave事件。我已经创建了Application_DocumentBeforeSave事件,但我想要文档保存后的事件。

有人能帮我解决这个问题吗?

提前感谢。

1个回答

6
private void Application_DocumentBeforeSave(Document Doc, ref bool SaveAsUI, ref bool Cancel)
{
    new Thread(() =>
    {
        while (true)
        {
            try
            {
                var application = document.Application; // This is inaccessible while the save file dialog is open, so it will throw exceptions.
                while (application.BackgroundSavingStatus > 0) // Wait until the save operation is complete.
                    Thread.Sleep(1000);
                break;
            }
            catch {
                Thread.Sleep(1000);
            }
        }
        // If we get to here, the user either saved the document or canceled the saving process. To distinguish between the two, we check the value of document.Saved.
        Application_DocumentAfterSave(document, !document.Saved);
    }).Start();
}

private void Application_DocumentAfterSave(Document Doc, bool isCanceled) {
    // Handle the after-save event. Note: Remember to check isCanceled.
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接