简体   繁体   English

我应该在 C# 中触发哪个事件来编写新创建的 excel 文件?

[英]Which event should I fire in C# for programming a newly created excel file?

If we want to fire an event when a user hits the save button, we use Globals.ThisAddIn.Application.WorkbookAfterSave += Application_WorkbookAfterSave;如果我们想在用户点击保存按钮时触发一个事件,我们使用 Globals.ThisAddIn.Application.WorkbookAfterSave += Application_WorkbookAfterSave;

Similarly, when we want to fire an event when a user opens a saved file, we use Globals.ThisAddIn.Application.WorkbookOpen += Application_WorkbookOpen;类似地,当我们想在用户打开保存的文件时触发事件时,我们使用 Globals.ThisAddIn.Application.WorkbookOpen += Application_WorkbookOpen;

My question is, which event should we use when a user creates a new file and it is not saved yet.我的问题是,当用户创建新文件但尚未保存时,我们应该使用哪个事件。 If there's no such event, please tell me anyway of achieving my task of doing some programming as soon as user creates a new excel file.如果没有这样的事件,请告诉我无论如何要在用户创建新的 excel 文件后立即完成我的一些编程任务。

Looks like you are interested in the NewWorkbook event of the Application class in Excel.看起来您对 Excel 中 Application 类的NewWorkbook事件感兴趣。

  ((Excel.AppEvents_Event)Application).NewWorkbook += new Microsoft.Office.Interop.Excel.AppEvents_NewWorkbookEventHandler(ThisWorkbook_NewWorkbook);


  // the event handler
  void ThisWorkbook_NewWorkbook(Microsoft.Office.Interop.Excel.Workbook Wb)
  {
      MessageBox.Show("New workbook" + Wb.Name);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM