When I want to get the value of a box that contains a formula
box.value I get the formula and not the number inside the box
How can I refer to the number inside the box and not the formula inside it?
OpenPyxl does not evaluate the formulas if you open the excel with openpyxl.load_workbook(fichero)
, like it says here in your documentation. In that case you have no way to access the numeric value.
But if you open it with openpyxl.load_workbook(fichero, data_only=True)
, it does the opposite. The attribute .value
of each cell gives you its numerical value and in this case you have no way to access the formula. Care because even in this case openpyxl
does not evaluate the formula, but instead reads a value that Excel saved there the last time you evaluated it. If with openpyxl
you change the data of some cell, the values of the cells with formulas are not updated .
If you need both, you should open the sheet twice in two different instances that you could process in parallel.
If you only want the data and not manipulate the Excel, and you will have to process them in some way later, I recommend using Pandas, which uses openpyxl below to read the Excel and then provides you with a much more useful DataFrame to visualize the data and obtain statistics, graphs, etc.