有没有办法知道用户是否更改了 excel 中的单元格值并且 python 可以对此做出反应?
我不知道常用的方法。但是你可以这样做: 您可以将要检查的单元格的值和名称保存在 txt 中。 然后不时用 python 检查单元格是否仍然具有 txt 中写入的值。
你可以使用 xlwings 库。
代码可能不同,但有一个代码来自我的一个项目:
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)