Python openpyxl data_only=True 返回 None [英] Python openpyxl data_only=True returning None
问题描述
我有一个简单的 excel 文件:
I have a simple excel file:
A1 = 200
A2 = 300
A3 = =SUM(A1:A2)
此文件在 excel 中工作并显示 SUM
的正确值,但是在将 openpyxl 模块用于 python 时,我无法在 data_only=True
模式下获取值
this file works in excel and shows proper value for SUM
, but while using openpyxl module for python I cannot get value in data_only=True
mode
来自 shell 的 Python 代码:
Python code from shell:
wb = openpyxl.load_workbook('writeFormula.xlsx', data_only = True)
sheet = wb.active
sheet['A3']
<Cell Sheet.A3> # python response
print(sheet['A3'].value)
None # python response
同时:
wb2 = openpyxl.load_workbook('writeFormula.xlsx')
sheet2 = wb2.active
sheet2['A3'].value
'=SUM(A1:A2)' # python response
任何建议我做错了什么?
Any suggestions what am I doing wrong?
推荐答案
这取决于文件的出处.data_only=True
取决于 Excel 等应用程序缓存的公式的值.但是,如果该文件是由 openpyxl 或类似库创建的,则很可能从未计算过该公式,因此没有可用的缓存值,openpyxl 将报告 None
作为该值.
It depends upon the provenance of the file. data_only=True
depends upon the value of the formula being cached by an application like Excel. If, however, the file was created by openpyxl or a similar library, then it's probable that the formula was never evaluated and, thus, no cached value is available and openpyxl will report None
as the value.
这篇关于Python openpyxl data_only=True 返回 None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!