I have a requirement I need find, replace and Save As to create multiple .xlxs Excel sheet from one sheet, the requirement is wherever I find a text "202" replace it with (203......290) and save as with same name.
I wrote a code in python where I am successfully able to replace the string and save the file, but the problem is as below:
- On Blank cells now
"None"is printed. - If I put a
ifconditionif s=="None":ws.cell(r,c).value=s.replace("None",str(''))
I am successfully able to see blank cells but other cells which has none value originally is now blank. - Any integer value is also like string.
import openpyxl
from openpyxl.utils.cell import get_column_letter
for value in range(204, 205):
wb=openpyxl.load_workbook("location of script\\sample.xlsx")
for i in wb.sheetnames:
ws = wb[i]
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":
ws.cell(r,c).value=s.replace("None",str(''))
elif "202 in s":
ws.cell(r,c).value=s.replace("202",str(value))
print("row{} col{}: {}".format(r,c,s))
wb.save("location of script"+str(value)+'sample'+'.xlsx') .
Request you to please help me to edit code so that I can following requirement:
- Blank cell should not have any value.
- Cells which are Integer should remain integer
- or if you other suggestion like writing Macro