Python openpyxl data_only =真返回无 [英] Python openpyxl data_only=True returning None

查看:409
本文介绍了Python openpyxl data_only =真返回无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的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 =真返回无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆