【问题标题】:How to add some parameters to WorkbookBeforeClose() event of Excel如何向 Excel 的 WorkbookBeforeClose() 事件添加一些参数
【发布时间】:2014-04-07 02:59:03
【问题描述】:
Excell应用程序的

WorkbookBeforeClose事件有2个参数:(Workbook Wb, ref bool Cancel)。我想将Excel.Application excellApp 之类的第三个参数添加到该事件中。 Here 是将另一个参数传递给事件的方式。我试过了:

excelApp.WorkbookBeforeClose += new AppEvents_WorkbookBeforeCloseEventHandler((wb, c) => mamed(wb, c, excelApp ));

但我得到错误,例如 参数 2 必须使用 'ref' 关键字声明。我也是added 'ref'关键字,但是没有任何结果。

我该如何解决这个问题?

【问题讨论】:

    标签: c# excel office-interop excel-interop


    【解决方案1】:

    你需要用ref关键字声明取消参数(c):

    excelApp.WorkbookBeforeClose += new Excel.AppEvents_WorkbookBeforeCloseEventHandler(
        (Excel.Workbook wb, ref bool c) => mamed(wb, c, wb.Application)
        );
    

    【讨论】:

    • 请教一个问题:我的 mamed() 事件返回“对象”。我应该在那里返回什么?在该方法中,我只执行应用程序关闭操作。
    • @JhoonBey - 返回值被忽略,所以如果你没有在其他任何地方使用它,你可以返回任何东西(例如 null),或者将方法签名更改为 void。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多