Home > Net >  updating cell's value in excel file using openpyxl without over writing with python
updating cell's value in excel file using openpyxl without over writing with python

Time:12-09

I want to update cell in excel file without over writing . I want to insert the new data into the same cell. the following code as example: the old value is "RAI", I want to add "ANKIT" without over writing. so the cell's value become : "RAI", "ANKIT"

# import openpyxl module
import openpyxl

wb = openpyxl.Workbook()

sheet = wb.active

c1 = sheet.cell(row = 1, column = 1)

c1.value = "ANKIT"

wb.save("C:\\Users\\user\\Desktop\\demo.xlsx")

CodePudding user response:

Try this:

if c1.value:
    c1.value = c1.value   "\n"   "ANKIT"
else:
    c1.value = "\n"   "ANKIT"
  • Related