openpyxl标题标题的字体大小& y_axis.title [英] openpyxl chage font size of title & y_axis.title

查看:665
本文介绍了openpyxl标题标题的字体大小& y_axis.title的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在努力更改y轴标题的字体&图表标题本身.

I am currently struggling with changing the font of y axis title & the charts title itself.

我尝试创建字体设置&将其应用于标题-从来没有运气过.

I have tried to create a font setting & applying it to the titles - with no luck what so ever.

new_chart.y_axis.title = chart_dict['y_title']
ft = Font(name='Calibri',
          size=11,
          bold = False,
          italic = False,
          vertAlign = None,
          underline = 'none',
          strike = False,
          color = 'FF000000')

new_chart.y_axis.title.font = ft

对此有任何简单的设置吗?

Is there any easy setting for this - like:

chart.y_axis.title.some_size_attrib = 12

还是我走错了方向?

推荐答案

我希望它不会使您太迟.经过大量研究,我能够找到一种使用Openpyxl从图表段更改字体及其大小的方法.

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.

字体大小定义为sz = 1500,这表示通常的15种字体大小.使用该逻辑1200时为12.最小值为100,最大值为400000.

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)])

这篇关于openpyxl标题标题的字体大小& y_axis.title的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆