0

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
not_speshal
  • 22,093
  • 2
  • 15
  • 30
  • See https://stackoverflow.com/questions/23350581/openpyxl-1-8-5-reading-the-result-of-a-formula-typed-in-a-cell-using-openpyxl -- you'll need to use something like [pycel](https://github.com/stephenrauch/pycel) or [xlwings](https://www.xlwings.org/) – Joshua Voskamp Nov 11 '21 at 21:03
  • 1
    Does this answer your question? [Openpyxl 1.8.5: Reading the result of a formula typed in a cell using openpyxl](https://stackoverflow.com/questions/23350581/openpyxl-1-8-5-reading-the-result-of-a-formula-typed-in-a-cell-using-openpyxl) – Joshua Voskamp Nov 11 '21 at 21:05

0 Answers0