我尝试遵循这个question https://stackoverflow.com/questions/39195957/write-formula-to-excel-with-python使用 python 和 openpyxl 包在我的 Excel 中添加一些公式。
该链接是我完成任务所需的链接。
但在这段代码中:
for i, cellObj in enumerate(Sheet.columns[2], 1):
cellObj.value = '=IF($A${0}=$B${0}, "Match", "Mismatch")'.format(i)
我犯了一个错误Sheet.columns[2]
知道为什么吗?我遵循完整的代码。
我有 python 2.7.13 版本,如果这有助于解决此错误。
****更新****
完整代码:
import openpyxl
wb = openpyxl.load_workbook('test1.xlsx')
print wb.get_sheet_names()
Sheet = wb.worksheets[0]
for i, cellObj in enumerate(Sheet.columns[2], 1):
cellObj.value = '=IF($A${0}=$B${0}, "Match", "Mismatch")'.format(i)
错误信息 :
for i, cellObj in enumerate(Sheet.columns[2], 1):
类型错误:“生成器”对象没有属性“getitem'