1

I am trying to use a python code to alter a single value in excel sheet and based on that value, certain calculations are being performed on the sheet itself. Finally, I need to read the answer but instead of the value, it is giving me the formula.

import math
import openpyxl
M, Vb = 0, 0
wb = openpyxl.load_workbook(r"calc.xlsx")
data_sheet = wb['Sheet2']
calc_sheet = wb['Sheet1']
Vb = data_sheet.cell(row=2,column=1).value
calc_sheet.cell(row=30,column=4).value = Vb
wb.save(r"calc.xlsx")
M = calc_sheet.cell(row=26,column=4).value
print(M)

it returns P33 rather than the numerical value.

  • You need to use a flag `data_only=True` - check this out https://stackoverflow.com/a/35624928/5585424 – Ankush Rathi Jun 20 '18 at 06:04
  • Possible duplicate of [Read Excel cell value and not the formula computing it -openpyxl](https://stackoverflow.com/questions/28517508/read-excel-cell-value-and-not-the-formula-computing-it-openpyxl) – Ash Sharma Jun 20 '18 at 06:22
  • it converts the formulas to values and then it is not reusable. I want to iteratively change a value. – Kartik Agrawal Jun 20 '18 at 06:30
  • The word "Excel" really should have been in the title somewhere. – HeinzKurt Jun 20 '18 at 06:32

0 Answers0