Deyaa
Deyaa

Reputation: 143

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

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")

Upvotes: 0

Views: 5936

Answers (1)

ljdyer
ljdyer

Reputation: 2086

Try this:

if c1.value:
    c1.value = c1.value + "\n" + "ANKIT"
else:
    c1.value = "\n" + "ANKIT"

Upvotes: 1

Related Questions