python对excel单元格数据进行修改

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)  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值