Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Excel cell value and not the formula computing it -openpyxl

I am using openpyxl to read cell value (excel addin-webservice update this column. )

I have used data_only = True but it is not showing the current cell value instead it is the value stored the last time Excel read the sheet.

wbFile = openpyxl.load_workbook(filename = xxxx,data_only=True) wsFile = wbFile[c_sSheet] 

How can i read the cell actual value ?

like image 222
user3411047 Avatar asked Feb 14 '15 16:02

user3411047


People also ask

How do I display cell values in formula instead of references?

You can do this using F9 in the formula bar: If you select/highlight any term in your formula and press F9 , it will get evaluated and the value is shown instead of the term. E.g. in your example, if you highlight A1 your formula will become =2+B1 .


2 Answers

wb = openpyxl.load_workbook(filename, data_only=True) 

The data_only flag helps.

like image 122
Marcin Kajzler Avatar answered Oct 08 '22 13:10

Marcin Kajzler


As @alex-martelli says, openpyxl does not evaluate formulae. When you open an Excel file with openpyxl you have the choice either to read the formulae or the last calculated value. If, as you indicate, the formula is dependent upon add-ins then the cached value can never be accurate. As add-ins outside the file specification they will never be supported. Instead you might want to look at something like xlwings which can interact with the Excel runtime.

like image 37
Charlie Clark Avatar answered Oct 08 '22 12:10

Charlie Clark