标签:ffffff ges exce term row 代码 def .com 题目
题目:现在假设表格中Celery,Garlic,Lemon这三个商品的单价设置错误,请更新表格设置新的价格:
Celery 1.19
Garlic 3.07
Lemon 1.27
代码
import openpyxl
def modify(sheet,name,value):
for index,row in enumerate(sheet.rows):
if name == sheet[‘A‘+str(index+1)].value:
sheet.cell(row=index+1,column=2,value=value)
try:
wb = openpyxl.load_workbook(‘produceSales.xlsx‘)
sheet = wb[wb.active.title]
modify(sheet,‘Celery‘,1.19)
modify(sheet,‘Garlic‘,3.07)
modify(sheet,‘Lemon‘,1.27)
wb.save(‘produceSales.xlsx‘)
except Exception as e:
print(‘修改表格出错!‘,‘\n‘,e)
else:
print(‘修改数据成功......‘)
运行截图
标签:ffffff ges exce term row 代码 def .com 题目
原文地址:http://blog.51cto.com/13885935/2172720