Get value from an Excel cell with Openpyxl (Python)

Asked

Viewed 848 times

-1

I have a spreadsheet in Excel that I am analyzing some data, and when I do this loop, the returned value is a string, like '=AL35/AH35' for example, instead of a float.

This set of cells I’m referring to has this formula and in the spreadsheet the result is a percentage.

At the end of the loop, I am saving the information in a file . txt.

for i in range(4,37):    

        previsao = metas['Metas'].cell(row = i, column = 39).value      

        file.write(f"{previsao:>15}\n")

I would like the output to Python to be a floating point value.

1 answer

0

Using the parameter data_only when opening the Workbook:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.