TypeError: 'NoneType' object is not callable: This shows up when I am trying to work with an excel file in Python using openpyxl
TypeError: 'NoneType' object is not callable: This shows up when I am trying to work with an excel file in Python using openpyxl
当我尝试 运行 以下代码时,第 11 行弹出错误 "TypeError: 'NoneType' object is not callable"。使用调试器,我很确定文件夹中的文件已被提取,所以我认为这不是问题所在。
import openpyxl
from math import cos
wb = openpyxl.load_workbook('data.xlsx')
sheet1 = wb.active
#assigning new column name
sheet1.insert_cols(3)
sheet1.cell(row = 1, column = 3).value('y2 = cos(x)')
# Calculating the cos() of the values in row 1
for row in range(2,sheet1.max_row + 1):
sheet1.cell(row = row, column = 3).value = math.cos( sheet1.cell(row = row, column = 1) )
#-------------------------------------------------
Traceback (most recent call last):
File "...excelPractice.py", line 11, in <module>
sheet1.cell(row = 1, column = 3).value('y2 = cos(x)')
TypeError: 'NoneType' object is not callable
我是学习 Python 的新手,这是我第一次尝试 excel,所以如果能很好地解释如何解决和理解这个问题以避免将来出现问题,那就太好了!
您可能想要更改 .value()
表示法:
sheet1.cell(row = 1, column = 3, value='y2 = cos(x)')
您可以像这个例子一样使用 Worksheet.cell():
d = ws.cell(row=4, column=2, value=10)
当我尝试 运行 以下代码时,第 11 行弹出错误 "TypeError: 'NoneType' object is not callable"。使用调试器,我很确定文件夹中的文件已被提取,所以我认为这不是问题所在。
import openpyxl
from math import cos
wb = openpyxl.load_workbook('data.xlsx')
sheet1 = wb.active
#assigning new column name
sheet1.insert_cols(3)
sheet1.cell(row = 1, column = 3).value('y2 = cos(x)')
# Calculating the cos() of the values in row 1
for row in range(2,sheet1.max_row + 1):
sheet1.cell(row = row, column = 3).value = math.cos( sheet1.cell(row = row, column = 1) )
#-------------------------------------------------
Traceback (most recent call last):
File "...excelPractice.py", line 11, in <module>
sheet1.cell(row = 1, column = 3).value('y2 = cos(x)')
TypeError: 'NoneType' object is not callable
我是学习 Python 的新手,这是我第一次尝试 excel,所以如果能很好地解释如何解决和理解这个问题以避免将来出现问题,那就太好了!
您可能想要更改 .value()
表示法:
sheet1.cell(row = 1, column = 3, value='y2 = cos(x)')
您可以像这个例子一样使用 Worksheet.cell():
d = ws.cell(row=4, column=2, value=10)