Python Openpyxl循环修改具体值

Python Openpyxl Looping to modify specific value

我在使用 Openpyxl 循环和编辑特定单元格值时遇到问题。它会找到值,但不会编辑找到的值。

谢谢大家!

这是我的代码:

xls = openpyxl.load_workbook(str(package_path))

BacNet_Device = xls[str(site_name) + ' BACnet Objects']

for row in BacNet_Device.values:
    for value in row:
        if value == "Please Fill Out":
            value = "N/A"

您需要更新单元格;

for row in BacNet_Device.iter_rows():
    for cell in row:
        if cell.value == "Please Fill Out":
            BacNet_Device[cell.coordinate] = 'N/A'