我怎样才能发现Excel工作簿已关闭 [英] How can I find out, that an Excel-workbook was closed

查看:80
本文介绍了我怎样才能发现Excel工作簿已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写Excel"应用程序级别"使用C#加载项。


我需要将一些其他数据链接到工作簿,我将其保存在工作簿的CustomXMLParts部分中。另外我需要注册一些事件。


当工作簿关闭时,必须从每个打开的工作簿的静态DataObjects列表中删除此数据。此外,事件必须取消注册。


在AddInBase.Application类中,定义了一个名为WorkbookBeforeClose的事件。


但不幸的是,在此事件被触发后,Excel会显示一个对话框,用户可以在其中指定是否保存工作簿中的更改。该对话框具有"取消"功能。作为第三种选择。如果用户选择取消,则工作簿将不会关闭


这就是为什么我不能将此事件用于清理目的。由于即使工作簿保持打开也会执行清理。


我还需要了解哪些内容,工作簿确实关闭了?


问候,Helmut

解决方案

我目前正在编写Excel"应用程序级别"使用C#加载项。


我需要将一些其他数据链接到工作簿,我将其保存在工作簿的CustomXMLParts部分中。另外我需要注册一些事件。


当工作簿关闭时,必须从每个打开的工作簿的静态DataObjects列表中删除此数据。此外,事件必须取消注册。


在AddInBase.Application类中,定义了一个名为WorkbookBeforeClose的事件。


但不幸的是,在此事件被触发后,Excel会显示一个对话框,用户可以在其中指定是否保存工作簿中的更改。该对话框具有"取消"功能。作为第三种选择。如果用户选择取消,则工作簿将不会关闭


这就是为什么我不能将此事件用于清理目的。由于即使工作簿保持打开也会执行清理。


我还需要了解哪些内容,工作簿确实关闭了?


问候,Helmut









I am currently writing an Excel "application-level" Add-In using C#.

I need to link some additional data to a workbook, that I save in the CustomXMLParts section of the workbook. In addition I need to register to some Events.

When the workbook closes, this data has to be removed from a static List of DataObjects of each open workbook. Furthermore the events have to be unregistered.

In the AddInBase.Application class an Event called WorkbookBeforeClose is defined.

But unfortunately after this Event is fired, Excel shows a dialog where the user can specify whether the changes in the workbook shall be saved, or not. This dialog has "Cancel" as a third option. If the user chooses cancel, the workbook will not be closed.

That's why I can not use this Event for clean-up purposis. Since the clean up will then be performed, even if the workbook stays open.

What other posibilities do I have to find out, that a workbook did actually close?

Regards, Helmut

解决方案

I am currently writing an Excel "application-level" Add-In using C#.

I need to link some additional data to a workbook, that I save in the CustomXMLParts section of the workbook. In addition I need to register to some Events.

When the workbook closes, this data has to be removed from a static List of DataObjects of each open workbook. Furthermore the events have to be unregistered.

In the AddInBase.Application class an Event called WorkbookBeforeClose is defined.

But unfortunately after this Event is fired, Excel shows a dialog where the user can specify whether the changes in the workbook shall be saved, or not. This dialog has "Cancel" as a third option. If the user chooses cancel, the workbook will not be closed.

That's why I can not use this Event for clean-up purposis. Since the clean up will then be performed, even if the workbook stays open.

What other posibilities do I have to find out, that a workbook did actually close?

Regards, Helmut


这篇关于我怎样才能发现Excel工作簿已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆