XML bug when using dataLabels.numFmt

Issue #785 resolved
liuyuqian created an issue

I'm tring to change the format of datalabel in barcharts.Generated xlsx file will raise a XML error when change dataLabels.numFmt. I unziped a right xlsx file,the "numFmt" label is:

<c:numFmt formatCode="0%" sourceLinked="0"/>

and the "numFmt" label in generated xlsx is:

<numFmt val="0%"/><showVal val="1"/>

Demo codes:

from openpyxl import Workbook
from openpyxl.chart import BarChart, Series, Reference
from openpyxl.chart.label import DataLabelList
wb = Workbook(write_only=True)
ws = wb.create_sheet()

rows = [('Number', 'pct'),
    (2, 0.1),
    (3, 0.2),
    (4, 0.1),
    (5, 0.2),
    (6, 0.3),
    (7, 0.1)]
for row in rows:

chart1 = BarChart()
chart1.type = "col"
chart1.style = 10

data = Reference(ws, min_col=2, min_row=1, max_row=7, max_col=3)
cats = Reference(ws, min_col=1, min_row=2, max_row=7)
chart1.add_data(data, titles_from_data=True)

chart1.dataLabels = DataLabelList()


ws.add_chart(chart1, "A10")

Comments (2)

  1. Log in to comment