How to detect value in change in excel using python?

473 views Asked by At

Is there is way to know if the user changed a cells value in excel and python can react to it?

1

There are 1 answers

1
Dmitrii Malygin On

You can use the xlwings library.

The code can be difference, but there is a code from one of my projects:

import xlwings as xw

wb = xw.Book.active()
sheet = wb.sheets['Sheet1']
range_to_monitor = sheet.range('A1')
previous_value = range_to_monitor.value

while True:
    current_value = range_to_monitor.value
    if current_value != previous_value:
        print(f"Value changed from {previous_value} to {current_value}")
        previous_value = current_value
    else:
        xw.apps.active.api.Sleep(100)