python – openpyxl.load_workbook(file,data_only = True不起作用?

为什么x =“None”而不是“500”?
我已经尝试了我所知道的所有内容并搜索了1小时的答案……
感谢您的任何帮助!

import openpyxl

wb = openpyxl.Workbook()
sheet = wb.active
sheet["A1"] = 200
sheet["A2"] = 300
sheet["A3"] = "=SUM(A1+A2)"

wb.save("writeFormula.xlsx")

wbFormulas = openpyxl.load_workbook("writeFormula.xlsx")
sheet = wbFormulas.active
print(sheet["A3"].value)

wbDataOnly = openpyxl.load_workbook("writeFormula.xlsx", data_only=True)
sheet = wbDataOnly.active
x = (sheet["A3"].value)
print(x) # None? Should print 500?

解决方法:

documentation

openpyxl never evaluates formula

上一篇:「题解」agc031_e Snuke the Phantom Thief


下一篇:从工作簿复制列,粘贴第二个工作簿的第二张,openPyXL