Detect when rows have been deleted by user in Excel 2003

こ雲淡風輕ζ 提交于 2019-12-11 09:16:50

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5800886/detect-when-rows-have-been-deleted-by-user-in-excel-2003

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!