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);}}