简体   繁体   English

使用 openpyxl 更新 excel 文件中的单元格值,而不用 python 覆盖

[英]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.我想更新 excel 文件中的单元格而不过度写入。 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.以下代码为例:旧值为“RAI”,我想添加“ANKIT”而不过度写入。 so the cell's value become: "RAI", "ANKIT"所以单元格的值变成:“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")

Try this:尝试这个:

c1.value = c1.value + "\n" + ANKIT"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM