scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.35k stars 510 forks source link

How to change the color of hyperlink text? #821

Open 602303068 opened 2 years ago

602303068 commented 2 years ago

How do I change the color of hyperlink text? Now add a hyperlink and use color The RGB setting has no effect. It is always the default blue color

gradinarnn commented 1 year ago

I can't find the answer to this question either

cowquant commented 9 months ago

Color written in the xml. Previewed with the correct color, wrong after open the pptx. Need help, thanks.

scanny commented 9 months ago

Post the minimum reproducible example of the code you used that's not behaving as you expect. https://stackoverflow.com/help/minimal-reproducible-example

cowquant commented 9 months ago

Hyperlink color and underline not work, still default blue. hyperlink has no font property. Python version: 3.11.4 python-pptx: 0.6.23

prs = Presentation() blank_slide_layout = prs.slide_layouts[6] slide = prs.slides.add_slide(blank_slide_layout)

txBox = slide.shapes.add_textbox(Inches(1), Inches(1), Inches(8), Inches(1)) tf = txBox.text_frame

p = tf.paragraphs[0] r = p.add_run() r.text = "Test test."

hlink = r.hyperlink hlink.address='http://www.github.com'

font = r.font font.size = Pt(20) font.color.rgb = RGBColor(0, 255, 0) font.underline = False

prs.save('test.pptx')

scanny commented 9 months ago

Hmm, post what you get from print(r.xml) placed just before prs.save() and lets have a look at that ...