Skip to content

Setting data_labels.position = XL_LABEL_POSITION.RIGHT breaks opening the presentation in Office 365 (web) #1134

@madflow

Description

@madflow
  • Setting data_labels.position = XL_LABEL_POSITION.RIGHT breaks opening the presentation in Office 365 (web).
  • It works in Keynote and Libreoffice.
  • Opening and saving in Libreoffice also fixes opening the file.
  • I cannot be "repaired" by Office 365
  • Working: charts_position_working.pptx
  • Broken: charts_position_right.pptx
Image

Given this working test script:

from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE, XL_LABEL_POSITION
from pptx.util import Inches


def main() -> None:
    # create presentation with 1 slide ------
    prs = Presentation()
    slide = prs.slides.add_slide(prs.slide_layouts[5])

    # define chart data ---------------------
    chart_data = CategoryChartData()

    chart_data.categories = ["East", "West", "Midwest"]
    chart_data.add_series("Series 1", (19.2, 21.4, 16.7))

    # add chart to slide --------------------
    x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
    chart = slide.shapes.add_chart(XL_CHART_TYPE.BAR_CLUSTERED, x, y, cx, cy, chart_data).chart

    plot = chart.plots[0]
    plot.has_data_labels = True
    data_labels = plot.data_labels
    data_labels.position = XL_LABEL_POSITION.OUTSIDE_END
    # CHANGEME: data_labels.position = XL_LABEL_POSITION.RIGHT

    category_axis = chart.category_axis
    category_axis.reverse_order = True

    prs.save("charts.pptx")


if __name__ == "__main__":
    main()

Workaround is for me: do not use "RIGHT".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions