-1

I'm trying to compute data from some excel files by using the library openpyxl.

And am now in trouble with the cell.value of functions or equations.

eg:

I may have such two cell.value below:

ws = openpyxl.load_work(xl_path)['Sheet1']
print(ws['B1'].value)
print(ws['B2'].value)
[output:]
= A1+A2    # Actually, the true value may be 1(A1) + 2(A2) -> 3
= A2*A4    # Actually, the true value may be 1(A1) * 4(A4) -> 4

And when I compute it , I got is not what I want:

ws['C1'].value = ws['B2'].value + ws['B1'].value 
print(ws['C1'].value)

I got a string result that concat str format value of this two cell.value:

[output:]
= A1+A2= A2*A4

I know some methods to get the true value of cells not functions or equations by using some 3rd party library , such as pandas.

But I wanna search a way just use the openpyxl.

ShinNShirley
  • 368
  • 2
  • 17

1 Answers1

1

The only way to operate with the actual values, and not formulae, with OpenPyXl is by opening that workbook with

load_workbook(xl_path, data_only = True)

This will open the exact same workbook but all cells will only be have their calculated values.

Read Excel cell value and not the formula computing it -openpyxl