from openpyxl import Workbook
from openpyxl import load_workbook
file_home = r'D:\FP\FBST.xlsx'
wb = load_workbook(filename=file_home)
sheet_ranges = wb['检测管1']
ws = wb['检测管1']
s=0
for c in range(0,41):
c+=1
print(sheet_ranges['a'+str(c)].value)
ws['a'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s).zfill(4))
ws['b'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+1).zfill(4))
ws['c'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+2).zfill(4))
ws['d'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+3).zfill(4))
ws['e'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+4).zfill(4))
ws['f'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+5).zfill(4))
ws['g'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+6).zfill(4))
ws['h'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+7).zfill(4))
ws['i'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+8).zfill(4))
ws['j'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+9).zfill(4))
ws['k'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+10).zfill(4))
ws['l'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+11).zfill(4))
ws['m'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+12).zfill(4))
ws['n'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+13).zfill(4))
ws['o'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+14).zfill(4))
ws['p'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+15).zfill(4))
ws['q'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+16).zfill(4))
ws['r'+str(c)]=(sheet_ranges['a'+str(c)].value)[0:-4] + (str(c+s+17).zfill(4))
s+=35
wb.save(file_home)
python对excel单元格数据进行修改
最新推荐文章于 2023-10-27 11:21:28 发布