Updating excel document using python

we already have an excel document namely produceSales and we need to update it with new values.Without searching each item we can done it through python programming

Code:

import openpyxl

wb=openpyxl.load_workbook(‘produceSales.xlsx’)

print(‘—-workbook opened—‘)

produce_update={‘Garlic’: 3.07,’Celery’: 1.19,’Lemon’: 1.27}

sheet=wb[‘Sheet’]

for rows in range(2,sheet.max_row+1):

  product=sheet.cell(row=rows,column=1).value

  if product in produce_update:

    sheet.cell(row=rows,column=2).value=produce_update[product]

wb.save(‘updatedProduceSales.xlsx’)

print(“Update completed”)

Leave a comment

Your email address will not be published. Required fields are marked *