如果我按评论的方式来做,那就很好了。
但是为了稍微清理代码,我做了一个函数来完成它。
但如果我试着用函数的方式做,
我得到Openpyxl - 'MergedCell'
对象属性'value‘是只读的:
"Traceback (most recent call last):
File "c:/Users/vitor.augusto/Desktop/projeto_robozinho/robot_api/excel.py", line 67, in <module>
preenche_linha(nr_solicitacao, 'D', start+1, 'center', 'total', ws)
File "c:\Users\vitor.augusto\Desktop\projeto_robozinho\robot_api\functions\utils.py", line 31, in preenche_linha
ws[f'{coluna}{linha}'] = valor
AttributeError: 'MergedCell' object attribute 'value' is read-only"
发布于 2022-05-12 01:46:55
我不打算比较这两个代码片段,只是假设错误可能是什么。
wsf'{column}{row}'引用的单元格很可能是合并单元格集的一部分,但不是左上角单元格,因此无法写入。
例如,我将单元格A1、B1和C1合并在一个工作表中。单元格A1是左上角单元格,是现在合并的单元格坐标,B1和C1实际上不再存在。如果我试图在B1或C1中输入一个值
column = 2
row = 1
ws[f'{column}{row}'] = value
这将导致AttributeError:'MergedCell‘对象属性'value’是只读错误。
检查发生错误时传递给函数的列和行的代码值。
https://stackoverflow.com/questions/72205263
复制相似问题