为什么我不能使用python和openpyxl更改excel中的单元格值?

时间:2018-02-18 00:41:42

标签: python excel 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中没有任何变化。这是为什么?

1 个答案:

答案 0 :(得分:2)

您需要保存文件:

<oauth>
    <error_description>
        Full authentication is required to access this resource
    </error_description>
    <error>unauthorized</error>
</oauth>

请参阅链接here的文档中的保存到文件