[英]Why can't I change the cell value in excel using python and openpyxl?
我沒有太多的代碼:
wb = openpyxl.load_workbook(r"C:\Users\julia\demographics.xlsx")
sheets = wb.sheetnames
ws = wb[sheets[0]]
for i in range(2, 26664):
fileCell = "A" + str(i)
currentFileName = str(ws[fileCell].value)
startFile, ext = os.path.splitext(currentFileName)
ext = ".png"
ws[fileCell].value = startFile + ext
print(ws[fileCell].value)
如您所見,我正在嘗試將每個圖片文件從“ .jpg”重命名為“ .png”,並且每個單元格都位於第一行(A行)。 當我打印“ ws [fileCell] .value”時,它按預期工作,並將每個單元格值打印為[filename] .png,但是在excel中,沒有任何變化。 為什么是這樣?
您需要保存文件:
filename = '' # This can be the same filename or a different one
wb.save(filename)
請參閱此處鏈接的文檔中的保存到文件 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.