How to Access the Real Value of a Cell Using the Openpyxl Module for Python

Openpyxl 1.8.5: Reading the result of a formula typed in a cell using openpyxl

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.

Cant open cells using openpyxl

Use .value to get information from a cell. Here is the corrected code:

import openpyxl as xl
wb = xl.load_workbook('transactions.xlsx')
sheet = wb['Sheet1']
cell = sheet.cell(1, 1)
print(cell.value)

Identifying cell in Openpyxl

cell.coordinate will return the cells address in "A1" style.

cell.row and cell.column should give you the addresses you need. Here is what I got from the documentation: https://openpyxl.readthedocs.org/en/latest/api/openpyxl.cell.html?highlight=.row#module-openpyxl.cell.cell
It gives you the list of attributes of a cell object.

I want to read a cell value, not its formula

According to How to access the real value of a cell using the openpyxl module for python
when loading the workbook you have to set data_only to True: wb = load_workbook("file.xlsx", data_only=True)



Related Topics



Leave a reply



Submit