当前位置: 代码迷 >> 综合 >> vsto workbook关闭点击确认保存触发函数
  详细解决方案

vsto workbook关闭点击确认保存触发函数

热度:98   发布时间:2024-03-09 01:19:11.0
 private void ThisAddIn_Startup(object sender, EventArgs e){app.WorkbookBeforeClose += WorkbookBeforeClose;
} private void WorkbookBeforeClose(Workbook Wb, ref bool Cancel){try{app.DisplayAlerts = false;if (!Wb.Saved){switch (MessageBox.Show(text: $"是否保存对'{this.Application.ActiveWorkbook.Name}'的更改?",caption: "Microsoft Excel", buttons: MessageBoxButtons.YesNoCancel, icon: MessageBoxIcon.Exclamation)){case DialogResult.Cancel:{Cancel = true;return;}case DialogResult.Yes:{//点击yes触发对应的事件                               Wb.Save();break;}case DialogResult.No:{Wb.Saved = true;break;}}}}catch (Exception ex){LogManager.WriteError("FCK", ex.StackTrace);}}