I'm a programming beginner.
I have an XLSXFILE to calculate some value by using equations. So, I wrote the code like below.
import openpyxl
import math
#Load file
XLSFILE = r"C:\Users\Name\PycharmProjects\Project_name\test.xlsx"
wb = openpyxl.load_workbook(XLSFILE, data_only=True)
ws_template = wb["Sheet1"]
#fill in value
for i in range (0, 61):
Ec = ws_template.cell(row=i+1, column=1)
Fc = -34.5*(2*(Ec/-0.002)-math.pow(Ec/-0.002, 2))
Fs = 206850*Ec
if Fs > 414:
Fs = 414
N = 62.9*Fc+1.6*Fs
ws_template.cell(row=i + 1, column=2).value = N
#Memorize file
wb.save(XLSFILE)
However, I can't conduct this program.
The error message is like this
TypeError: unsupported operand type(s) for /: 'Cell' and 'float'
What should I do to solve this problem?
Tips:
version: Python ver.3.6
you need to do math on the value of the cell, not on the cell object
use Ec.value
instead of EC
or Ec = ws_template.cell(row=i+1, column=1).value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.