问题
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