相关疑难解决方法(0)

将公式写入Excel时出现Python错误

我尝试按照这个问题使用 python 和 openpyxl 包在 excel 中添加一些公式。

该链接是我完成任务所需的链接。

但在这段代码中:

for i, cellObj in enumerate(Sheet.columns[2], 1):
    cellObj.value = '=IF($A${0}=$B${0}, "Match", "Mismatch")'.format(i) 
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会出错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)
Run Code Online (Sandbox Code Playgroud)

错误信息 :

for i, cellObj in enumerate(Sheet.columns[2], 1):
Run Code Online (Sandbox Code Playgroud)

类型错误:“生成器”对象没有属性“ getitem

python excel openpyxl

4
推荐指数
1
解决办法
4675
查看次数

标签 统计

excel ×1

openpyxl ×1

python ×1