我正在尝试将openpyxl散点图的线设置为绿色:
from openpyxl import *
book = workbook.Workbook()
ws = book.active
xRef = chart.Reference(ws, min_col=1, min_row=2, max_row=22)
yRef = chart.Reference(ws, min_col=2, min_row=2, max_row=22)
chart.Series(yRef, xvalues=xRef, title='test')
lineProp = drawing.line.LineProperties(solidFill = 'green')
series.graphicalProperties.line = lineProp
虽然此代码不会引起任何问题,但它不会更改默认线条的颜色。更改线条颜色的正确方法是什么?
有趣的是,我可以使用以下方式将样式设置为虚线或点划线:
lineProp = drawing.line.LineProperties(prstDash='dash')
series.graphicalProperties.line = lineProp
事实证明,线宽可以保持默认值。通过将solidFill
设置为openpyxl.drawing.colors.ColorChoice
的实例,我可以进行颜色更改:
lineProp = drawing.line.LineProperties(solidFill = drawing.colors.ColorChoice(prstClr='green'))