openpyxl写入excel原模板条件格式失效

img


在模板设置好负值条件格式条件格式如上,用openpyxl对模板写入数据保存为新excel后,打开后发现条件格式还在,但是负值数据条失效了,如下

img

请问如何解决,能让写入数据新文件保持原模板设置的条件格式的负值数据条

负值数据条失效了这个在哪里可以体现出来,
没从截图中看到相关信息,可以标注下吗

目前来说这个功能没你想的那么完善,不建议直接python操作excel可视化这块。如果要做建议用power BI 去搞或者用基础excel。

看看代码是否负值选错了颜色


>>> wb = load_workbook('document.xlsx')
>>> # Need to save with the extension *.xlsx
>>> wb.save('new_document.xlsm')
>>> # MS Excel can't open the document
>>>
>>> # or
>>>
>>> # Need specify attribute keep_vba=True
>>> wb = load_workbook('document.xlsm')
>>> wb.save('new_document.xlsm')
>>> # MS Excel can't open the document
>>>
>>> # or
>>>
>>> wb = load_workbook('document.xltm', keep_vba=True)
>>> # If us need template document, then we need specify extension as *.xltm.
>>> # If us need document, then we need specify attribute as_template=False.
>>> wb.save('new_document.xlsm', as_template=True)
>>> # MS Excel can't open the document