How to access the real value of a cell using the openpyxl module for python

user3455972 picture user3455972 · Mar 24, 2014 · Viewed 92.4k times · Source

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.

Thank you.


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

Answer

Iulian Stana picture Iulian Stana · Jan 22, 2015

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)

Good luck :)