我正在处理我的python脚本中的excel并收到以下错误:
Traceback (most recent call last):
File "script_consolidateExcels_v3.py", line 134, in <module>
colNum = findColOfCell(ws, "xxx", 1)
File "script_consolidateExcels_v3.py", line 28, in findColOfCell
if worksheet.cell(row=inRow, column=k).value == val:
AttributeError: 'MergedCell' object has no attribute 'value'
Excel文件最初具有合并的单元格,但是我使用Microsoft Excel取消了所有合并,但是仍然弹出此错误。我什至尝试了ws.unmerge_cells(),但没有帮助。 (非常奇怪,起初我在Windows笔记本电脑上编写并运行了脚本,但未弹出此错误...我将该脚本发送到了Mac,现在我收到了此错误...(我无法访问Windows笔记本电脑当前))
这里是有问题的部分:
def findColOfCell(worksheet, val, inRow, startCol=1):
i = 0
k = startCol
while i == 0:
if worksheet.cell(row=inRow, column=k).value == val:
i = 1
# here = ord(worksheet.cell(row=inRow, column=k).column)-64 # convert column letter to number
here = worksheet.cell(row=inRow, column=k).column
else: k += 1
return here