I do not work in a file that already has formulas in beginning. I've created the formulas in the same python file, by codes. And I want to read the values calculated by these formulas, however, whatever I do I don't succeed.
Example from my py file:
Column B is my CURRENCY TYPE column and has a formula in the code from first to the max row: =VLOOKUP(E:E, F3:G1500, 2, 0)
whatever...
As a result, when I open the saved xlsx file, created by my codes, I see currency types as USD, EUR and other, just as I want to see. However when I try to print, for example ws['B4'].value
, it outputs the value "=VLOOKUP(E:E, F3:G1500, 2, 0)" not the currency "USD".
I want to access that "USD" or "EUR" values because I will additionally use if
commands to work on them.
I have tried much, including data_only=True
, however it does not work, because I create formulas and read the values created by that formulas without saving and re-opening the excel file.
My code:
import openpyxl
wb = openpyxl.load_workbook('currency.xlsx')
ws = wb['KrediGeriOdeme']
ms = ws.max_row
first_column = ws['B']
for x in range(2, len(first_column)):
first_column[x].value = "=VLOOKUP(E:E, F3:G1500, 2, 0)".format(first_column)
print(ws['B3'].value)
Output:
=VLOOKUP(E:E, F3:G1500, 2, 0)
Expected output:
USD