import openpyxl
wb = openpyxl.load_workbook('/root/Desktop/produceSales.xlsx')
sheet = wb.active
infos = ([cell.value for cell in row] for row in sheet.rows)
dic = {'Celery':1.19, 'Garlic':3.07, 'Lemon':1.27}
for index, item in enumerate(infos):
if item[0] in dic:
sheet.cell(row=index+1, column=2, value=dic[item[0]])
wb.save(filename='/root/Desktop/produceSales.xlsx')
本文介绍了一个使用Python openpyxl库来批量更新Excel文件中特定产品价格的脚本。脚本读取'produceSales.xlsx'文件,根据预设的价格字典更新产品价格,并将更改保存回原文件。

505

被折叠的 条评论
为什么被折叠?



