飞鱼python 发表于 2021-4-26 19:44:34

恳请各位大神帮忙解决一下

# 导入模块
from openpyxl import load_workbook

# 获取数据
wb= load_workbook('./material/江宇工资信息表.xlsx')
ws = wb['Sheet1']
ws['H1'].value = '总工资'

for row in ws.iter_rows(min_row=2,max_row=11 ,values_only=True):
    performance = row
    bonus = row
    base = row

# 使用数据
    salary = performance + bonus + base
   


# 输出结果

wb.save('./material/江宇工资信息表.xlsx')


我该怎么样利用循环把所有人总工资都自动填入表格呀(具体是该怎么样赋值呢?)

txxcat 发表于 2021-4-26 22:17:55

本帖最后由 txxcat 于 2021-4-26 22:19 编辑

# 导入模块
from openpyxl import load_workbook

# 获取数据
wb= load_workbook('./material/江宇工资信息表.xlsx')
ws = wb['Sheet1']
ws['H1'].value = '总工资'

# for row in ws.iter_rows(min_row=2,max_row=11 ,values_only=True):
#   performance = row
#   bonus = row
#   base = row
   
for row in range(2,12):
    performance = ws['E'+str(row)].value
    bonus = ws['F'+str(row)].value
    base = ws['G'+str(row)].value
    salary = performance + bonus + base
    ws['H'+str(row)] = salary

# 输出结果

wb.save('./material/江宇工资信息表.xlsx')

飞鱼python 发表于 2021-4-27 20:12:44

txxcat 发表于 2021-4-26 22:17


谢谢,已经很好了,给我提供了很好的思路{:5_109:}
页: [1]
查看完整版本: 恳请各位大神帮忙解决一下