jmcnamara / XlsxWriter

A Python module for creating Excel XLSX files.
https://xlsxwriter.readthedocs.io
BSD 2-Clause "Simplified" License
3.66k stars 632 forks source link

Bug: Using leader_lines leads to corrupted Excel #1019

Closed sebastian2010 closed 1 year ago

sebastian2010 commented 1 year ago

Current behavior

When adding leader_lines than there is a left angle bracket too much in showLeaderLines tag which leads to a corrupted Excel file <<c15:showLeaderLines val="1"/>

Expected behavior

Valid Excel when using leader_lines

Sample code to reproduce

import xlsxwriter

workbook = xlsxwriter.Workbook("chart.xlsx")
worksheet = workbook.add_worksheet()

chart = workbook.add_chart({"type": "column"})

data = [[1, 2, 3, 4, 5]]

worksheet.write_column("A1", data[0])

chart.add_series(
    {
        "values": "=Sheet1!$A$1:$A$5",
        "data_labels": {
            "value": True,
            "position": "outside_end",
            "leader_lines": True,
            "font": {"name": "Arial", "size": 8},
        },
    }
)

worksheet.insert_chart("A7", chart)

workbook.close()

Environment

- XlsxWriter version: 3.1.8

Any other information

No response

OpenOffice and LibreOffice users

jmcnamara commented 1 year ago

I've added fixes to the Python and Rust test suites so that this (human) error shouldn't happen again. Thanks for the input.