How can I change the font on odfpy for example, using Arial or comic sans. I've seen some examples but they only use the params "fontsize" and "fontweight". I can't find any example changing the font and the param "font" doesn't seem to work.
Asked
Active
Viewed 376 times
1 Answers
0
Section 5.15.39 in api-for-odfpy.odt
lists the style.TextProperties
as:
5.15.39 style.TextProperties
Requires the following attributes: No attribute is required.
Allows the following attributes: backgroundcolor, color, condition, country,
countryasian, countrycomplex, display, fontcharset, fontcharsetasian,
fontcharsetcomplex, fontfamily, fontfamilyasian, fontfamilycomplex,
fontfamilygeneric, fontfamilygenericasian, fontfamilygenericcomplex, fontname,
fontnameasian, fontnamecomplex, fontpitch, fontpitchasian, fontpitchcomplex,
fontrelief, fontsize, fontsizeasian, fontsizecomplex, fontsizerel, fontsizerelasian,
fontsizerelcomplex, fontstyle, fontstyleasian, fontstylecomplex, fontstylename,
fontstylenameasian, fontstylenamecomplex, fontvariant, fontweight, fontweightasian,
fontweightcomplex, hyphenate, hyphenationpushcharcount, hyphenationremaincharcount, language, languageasian, languagecomplex, letterkerning, letterspacing, scripttype,
textblinking, textcombine, textcombineendchar, textcombinestartchar, textemphasize,
textlinethroughcolor, textlinethroughmode, textlinethroughstyle, textlinethroughtext,
textlinethroughtextstyle, textlinethroughtype, textlinethroughwidth, textoutline,
textposition, textrotationangle, textrotationscale, textscale, textshadow,
texttransform, textunderlinecolor, textunderlinemode, textunderlinestyle,
textunderlinetype, textunderlinewidth, usewindowfontcolor.
I assume they are accessible in the same way as fontsize
and fontweight
, as in:
h1style.addElement(TextProperties(attributes={'fontsize':"24pt",'fontweight':"bold" }))
Although, I personally have no intention of loading software this old to test it.

Rolf of Saxony
- 21,661
- 5
- 39
- 60
-
Use `'fontfamily':"Arial"` worked for me, thanks – user3476016 Dec 26 '20 at 18:11
-
@user3476016 My pleasure, welcome to StackOverflow! https://stackoverflow.com/help/someone-answers – Rolf of Saxony Dec 26 '20 at 19:33