OpenPyXL:尝试设置填充时的AttributeError

时间:2015-09-06 17:16:32

标签: python windows spreadsheet openpyxl

    ws.cell(row=greenBegin+1, column=3).style.fill.fill_type = 'solid'

    ws.cell(row=greenBegin+1, column=3).style.fill.start_color.index = '0000FF'

    ws.cell(row=greenBegin+1, column=3).style.fill.end_color.index = '0000FF'

我尝试使用此代码将单元格的填充设置为纯绿色,但我总是得到" AttributeError:无法设置属性"当我运行代码。我尝试了不同的造型方法,但是这个库AFAIK上没有很多信息,至少可以说是因为我将它用于工作项目。

1 个答案:

答案 0 :(得分:-1)

文档中对此进行了介绍。样式是不可变的,因此无法进行编辑。必须重新分配它们。

http://openpyxl.readthedocs.org/en/2.3.0-b1/styles.html

ws.cell(…).fill = Fill(…)