首页 新闻 搜索 专区 学院

openpyxl使用fills修改单元格的背景颜色后,再次load_workbook的时候总是失败

0
悬赏园豆:20 [已关闭问题] 关闭于 2018-07-13 16:41

使用openpyxl中的styles修改一个单元格的背景颜色,第一次运行程序可以修改背景颜色成功,但是再次运行这个python程序的时候,总是提示load_workbook失败,提示信息如下:

Traceback (most recent call last):
  File "e:\pythoncode\switch.py", line 218, in <module>
    wbbb = load_workbook(file_path)
  File "d:\Python27\lib\site-packages\openpyxl-2.5.0a2-py2.7.egg\openpyxl\reader\excel.py", line 222, in load_workbook
    apply_stylesheet(archive, wb) # bind styles to workbook
  File "d:\Python27\lib\site-packages\openpyxl-2.5.0a2-py2.7.egg\openpyxl\styles\stylesheet.py", line 182, in apply_stylesheet
    stylesheet = Stylesheet.from_tree(node)
  File "d:\Python27\lib\site-packages\openpyxl-2.5.0a2-py2.7.egg\openpyxl\styles\stylesheet.py", line 99, in from_tree
    return super(Stylesheet, cls).from_tree(node)
  File "d:\Python27\lib\site-packages\openpyxl-2.5.0a2-py2.7.egg\openpyxl\descriptors\serialisable.py", line 79, in from_tree
    obj = desc.from_tree(el)
  File "d:\Python27\lib\site-packages\openpyxl-2.5.0a2-py2.7.egg\openpyxl\descriptors\sequence.py", line 86, in from_tree
    return [self.expected_type.from_tree(el) for el in node]
  File "d:\Python27\lib\site-packages\openpyxl-2.5.0a2-py2.7.egg\openpyxl\styles\fills.py", line 65, in from_tree
    return super(Fill, cls).from_tree(child)
  File "d:\Python27\lib\site-packages\openpyxl-2.5.0a2-py2.7.egg\openpyxl\descriptors\serialisable.py", line 99, in from_tree
    return cls(**attrib)
TypeError: object() takes no parameters

看样子应该是load_workbook的时候加载表格的样式失败了,真心不知道咋解决这个问题。请各位大侠指教!

if __name__ == '__main__':
    wb = load_workbook(file_path)
   wsKaoqin = wb.get_sheet_by_name(KQetName)
     wsKaoqin.cell(row = 3, column = 1).fill = styles.fills.GradientFill(stop=['FFCC00', 'FFCC00'])
    wb .save(file_path)
summerise8090的主页 summerise8090 | 菜鸟二级 | 园豆:222
提问于:2018-03-23 15:11
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册