I'm trying to replace every occurrence of a given string with another string in a directory of excel files.
for (root, dirs, files) in os.walk(DIRECTORY):
for file in files:
if file.endswith(".xlsx"):
path = os.path.join(root, file)
print("Opening: " + path)
wb = openpyxl.load_workbook(path)
for ws in wb.worksheets:
for row in ws.iter_rows():
for cell in row:
print(cell.value)
if cell.value == target:
print("TARGET STRING FOUND")
cell.value = replace
wb.save(wb)
I get AttributeError: 'list' object has no attribute 'endswith' when I run the script.
Thanks for any help