[英]How to read merged cell values of an excel file with openpyxl / python?
I have been trying to read value of a merged cell by using openpyxl module. 我一直在尝试使用openpyxl模块读取合并单元格的值。 However, it gives below error:
但是,它给出以下错误:
if ws.cell(row=i, column=j).value == q.get(): #and ws.cell(row=i+1, column=j).value == 'tot.':
AttributeError: 'MergedCell' object has no attribute 'value' AttributeError:“ MergedCell”对象没有属性“ value”
What do you suggest? 你有什么建议? Thanks in advance!
提前致谢!
To avoid confusion MergedCells
have no values: they're only used for putting borders on ranges of merged cells and shouldn't really be considered cells. 为避免混淆,
MergedCells
没有值:它们仅用于在合并的单元格范围内设置边框,不应真正视为单元格。 Use hasattr(cell, "value")
or getattr(cell, "value", None)
使用
hasattr(cell, "value")
或getattr(cell, "value", None)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.