based on Find and Replace text in xlsx file with python openpyxl in whichever cell it appear in within sheet I tried to do the following:
The file "example.xlsx" contains cells where I want to replace "'path[file.xlsx]tab1'!A5" by "'path[file.xlsm]tab1'!A5". I tried:
#! python3
import openpyxl
wb = openpyxl.load_workbook("example.xlsx")
ws = wb["Sheet1"]
i = 0
for r in range(1,ws.max_row+1):
for c in range(1,ws.max_column+1):
s = str(ws.cell(r,c).value)
if s != None and "xlsx" in s:
ws.cell(r,c).value = s.replace("xlsx","xlsm")
print("row {} col {} : {}".format(r,c,s))
i += 1
wb.save('targetfile.xlsx')
print("{} cells updated".format(i))
But it did not replace anything. What shall I do?