Home>
environment

openpyxl: 3.0.5
Python 3.8.1

In the following cellsThe displayed charactersI want to get

In other words, I want to get the letters "V = 0.157m/sec".

The formula is embedded in this cell as shown below, and the value is determined by the condition of the value in other cells.

When I refer to the value of the Cell object to get this value,

print (type (cell))
#<class'openpyxl.cell.cell.Cell'>
print (cell.value)
# = IF (OR ($AL13 = "", $AL13 = "ERROR", ... (Omitted))

In that way, you will get the calculation formula.

Is there a way to get the displayed characters instead of the formula?

  • Answer # 1

    load_workbookWith a functiondata_only = TrueBy specifying the option, you can get the "value calculated when you last opened it in Excel".

    https://openpyxl.readthedocs.io/en/stable/api/openpyxl.reader.excel.html#openpyxl.reader.excel.load_workbook

    data_only (bool) – controls whether cells with formulae have either the formula (default) or the value stored the last time Excel read the sheet