Long time lurker, first time asker. If I'm missing something let me know.
I'm using python 35 and openpyxl 2.4.0. I've generated a number of charts in an xlsx file. Snippet below:
# create chart for summary graph
myChart = BarChart()
myChart.type = 'col'
myChart.style = 10
myChart.title = chartTitle # 'chartTitle' is passed to the function
myChart.y_axis.title = 'No. of WRs'
myChart.x_axis.title = 'WR assignee'
# some lines here omitted (related to charted data)
myChart.shape = 4
newSheet.add_chart(myChart, 'F1')
All works well, but the chart title and axis titles are 18 and 16 pt font - much too big for the chart size. I don't want to work on the chart size because I don't know in advance how many columns will be graphed - the script reads a weekly ERP dump and graphs specific results.
The openpyxl doc provides guidance on formatting cells, but none (that I can find) on text size within charts. Any help would be appreciated.
I hope it won't get you too late. After a lot of research I was able to find a way to change the font and its size from a chart segment using Openpyxl.
The size of the font is defined at the sz=1500 and this means the usual 15 font size. Using that logic 1200 is 12. The minimum is 100 and the maximum is 400000.
from openpyxl.chart.text import RichText
from openpyxl.drawing.text import Paragraph, ParagraphProperties, CharacterProperties, Font
font_test = Font(typeface='Calibri')
cp = CharacterProperties(latin=font_test, sz=1500)
chart.x_axis.txPr = RichText(p=[Paragraph(pPr=ParagraphProperties(defRPr=cp), endParaRPr=cp)])