注意:虽然我的问题与VSTO Word post post事件在同一个球场,但目标和目标(以及由此产生的所需代码)是不同的。 VSTO Word中的OP保存事件状态: 之后……
不,没有事件可以捕获任何保存或保存后的操作。唯一与储蓄有关的是 DocumentBeforeSave 。
DocumentBeforeSave确实提供了允许开发人员禁止内置UI(SaveAs对话框)以及取消触发事件的操作的参数。这允许开发人员提供自己的接口来保存(as)哪个 将 能够确定何时保存文档(as)并采取任何所需的操作,具体取决于文件名,扩展名或标准。
也可以使用Word的内置SaveAs对话框,而不是创建自己的对象框,尽管这在C#中有点四舍五入,因为它需要使用PInvoke。这是一个示例,让您了解这是如何工作的(未在移动设备上进行测试):
private void ThisDocument_BeforeSave(object sender, object e) { //Suppress the built-in SaveAs interface (dialog box) e.SaveAsUi = false; //Cancel the default action e.Cancel = true; Word.Dialog dlg = wdApplication.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFileSaveAs]; //Word dialog box parameters have to be accessed via Late-Binding (PInvoke) //To get the path, use the Name property object oDlg = (object)dlg; object[] oArgs = new object[1]; oArgs[0] = (object)@""; dlg.Show(ref missing); object fileName = oDlg.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, oDlg, oArgs); }
列出了可以使用的可用对话框参数 这里 。