如何使用适用于python的openpyxl模块访问单元格的实际值 [英] How to access the real value of a cell using the openpyxl module for python
本文介绍了如何使用适用于python的openpyxl模块访问单元格的实际值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对此我感到很麻烦,因为cell.value函数返回用于该单元格的公式,并且我需要在操作后提取Excel提供的结果.
I am having real trouble with this, since the cell.value function returns the formula used for the cell, and I need to extract the result Excel provides after operating.
谢谢.
好吧,我想我已经找到解决方法了;显然,要访问cell.internal值,您必须先前在工作表(这是"RawCell"的列表)中使用iter_rows().
Ok, I think I ahve found a way around it; apparently to access cell.internal value you have to use the iter_rows() in your worksheet previously, which is a list of "RawCell".
for row in ws.iter_rows():
for cell in row:
print cell.internal_value
推荐答案
就像查理·克拉克(Charlie Clark)已经建议您在加载工作簿时可以在True
上设置data_only
:
Like Charlie Clark already suggest you can set data_only
on True
when you load your workbook:
from openpyxl import load_workbook
wb = load_workbook("file.xlsx", data_only=True)
sh = wb["Sheet_name"]
print(sh["x10"].value)
祝你好运:)
这篇关于如何使用适用于python的openpyxl模块访问单元格的实际值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文