下面的代码实现了颜色设置、字体大小和数字格式。但是,我还不能旋转数据标签,因为我相信这个 API 在 python-pptx 0.6.5 中还不可用
lbl = plot.data_labels
lbl.font.size = config["DATA_LABEL_FONT_SIZE"]
lbl.font.color.rgb = config["DATA_LABEL_FONT_COLOR"]
lbl.number_format = config["DATA_LABEL_NUMBER_FORMAT"]
lbl.position = config["DATA_LABEL_POSITION"]
首先,我在旋转前后创建了两个最小的幻灯片,并使用 opc-diag 工具找出差异。
<a:bodyPr rot="-5400000" spcFirstLastPara="1" vertOverflow="ellipsis"
vert="horz" wrap="square" lIns="38100" tIns="19050" rIns="38100"
bIns="19050" anchor="ctr" anchorCtr="1">\n
<a:spAutoFit/>\n </a:bodyPr>\n
我相信我需要添加 rot="-5400000" XML 元素到 lbl (plot.data_labels),但不清楚如何实现这一点。我用过dir() , ._element和 .xml在图表及其子项上但无法找到 <a:bodyPr>标签。
请您参考如下方法:
我在下面尝试过,它有效。
if config["DATA_LABEL_VERTICAL"]:
txPr = lbl._element.get_or_add_txPr()
txPr.bodyPr.set('rot','-5400000')
