问题
Is it possible to set word wrap to false all data labels in my chart?
I was trying to do plots[0].data_labels.format.text_frame.word_wrap = False but data_labels hasn't format property
回答1:
Start with the DataLabels
object. This is available on the .data_labels
attribute of a plot or a series. You might want to try both to see what behavior you get:
from pptx.text.text import TextFrame
# ---obtain reference to <c:dLbls> element in question---
data_labels = plot2.data_labels
dLbls = data_labels._element
# ---use its <c:txPr> child to create TextFrame object---
text_frame = TextFrame(dLbls.get_or_add_txPr(), None)
# ---turn off word-wrap in the usual way---
text_frame.word_wrap = False
This can be made more compact, I show it step-by-step here for clarity.
来源:https://stackoverflow.com/questions/54353954/word-wrap-data-labels-python-pptx