检测 Excel 2003 中用户删除行的时间
我有一个 Excel 2003 的 C#.Net 插件。我希望有一个可以附加的钩子(事件?),以检测用户何时从活动工作表中删除一行或多行,因为某些缓存会发生这种情况时需要重新计算或丢弃。
有这样的钩子或事件吗?如果没有,有办法实现我想要的吗?
I have a C#.Net add-in to Excel 2003. I am hoping there is a hook (event?) to which I can attach, to detect when the user has deleted a row or rows from the active worksheet, as some caches will need to be recomputed or discarded when this happens.
Is there any such hook or event? If not, is there a way of achieving what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,似乎没有办法检测行何时被删除。根据工作表事件列表,您可以使用 Change 事件来找出某些内容已更改,然后循环遍历工作表中的所有行以找出已更改的内容和内容。相应地更新您的缓存。 这可以帮助您思考其他使用方式还有 Change 方法。
Unfortunately, there doesn't appear to be a way to detect when a row is deleted. According to the Worksheet event list, you could use the Change event to figure out that something has changed, then loop through all rows in the Worksheet to figure out what has changed & update your cache accordingly. This may help you think through other ways of using the Change method as well.
您可以尝试以下操作:
创建一个指向工作表中最远单元格(单元格 XFD1048576)的命名范围。
如果引发工作表更改事件,则测试此命名范围是否仍引用同一单元格。如果是这样,则没有插入或删除行或列,并且该事件指示某些其他更改(例如单元格值更改)。
如果此命名范围引用不同的地址,则行/列已被删除。
如果它返回 #REF 错误,则已添加行或列,并且指定范围的地址超出了最大值。在这两种情况下,请删除命名范围并重新创建它。
You can try the following:
Create a named range that points to the far most cell in the sheet (cell XFD1048576).
If a sheet change event is raised, then test if this named range still refers to the same cell. If so, no row or column has been inserted or deleted and the event indicates some other change (like a cell value change).
If this named range refers to a different address, then a row/column has been deleted.
If it returns a #REF error, then a row or column has been added and the named range's address exceeded the maximum. In both cases, delete the named range and recreate it again.