Openpyxl 1.8.5:使用openpyxl读取在单元格中键入的公式的结果 [英] Openpyxl 1.8.5: Reading the result of a formula typed in a cell using openpyxl
问题描述
我正在一张Excel工作表中打印一些公式:
I am printing some formula in one of the Excel sheets:
wsOld.cell(row = 1, column = 1).value = "=B3=B4"
但是我不能将其结果用于实现其他一些逻辑,例如:
But I cannot use its result in implementing some other logic, as:
if((wsOld.cell(row=1, column=1).value)='true'):
# copy the 1st row to another sheet
即使我试图在命令行中打印结果,我最终也会打印公式:
Even when I am trying to print the result in the command line, I end up printing the formula:
>>> print(wsOld.cell(row=1, column=1))
>>> =B3=B4
如何获取单元格中公式的结果,而不是公式本身?
How can I get the result of the formula in a cell and not the formula itself?
推荐答案
openpyxl支持公式或公式的值.您可以在打开工作簿时使用data_only
标志选择哪个.但是,openpyxl不会也不会计算公式的结果.那里有像pycel这样的库,据称可以做到这一点.
openpyxl support either the formula or the value of the formula. You can select which using the data_only
flag when opening a workbook. However, openpyxl does not and will not calculate the result of a formula. There are libraries out there like pycel which purport to do this.
这篇关于Openpyxl 1.8.5:使用openpyxl读取在单元格中键入的公式的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!