oox: only write showLeaderLines in dLbls for pie and doughnut charts

The OOXML standard defines <c:showLeaderLines> and <c:leaderLines>
as valid children of <c:dLbls> only for pie and doughnut chart types.
The export code wrote these elements unconditionally for all chart
types, including bar charts. Excel crashes when it encounters these
elements inside a barChart series dLbls.

For non-pie/doughnut charts, the c15:showLeaderLines extension
(from the Office 2013 chart extensions namespace) is the correct
mechanism to express leader lines. The code already had logic to
write this extension for non-pie charts, but it was written in
addition to the invalid standard elements rather than instead of
them.

Fix by guarding <c:showLeaderLines> and <c:leaderLines> behind a
pie/doughnut check, and writing only the c15 extension for all
other chart types.

Change-Id: I652927b8d29de159a3bda10461bc220affe93dd9
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/778
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 9a52b0c1633108022e58605f6732ad81160a9bb1)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204677
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Ujjawal Kumar
2026-05-04 09:38:17 +02:00
committed by Xisco Fauli
parent ba2b98774c
commit b43eb71a3c
3 changed files with 26 additions and 16 deletions
+22 -12
View File
@@ -5690,22 +5690,32 @@ void ChartExport::exportDataLabels(
if (!bIsChartex) {
bool bShowLeaderLines = false;
xPropSet->getPropertyValue(u"ShowCustomLeaderLines"_ustr) >>= bShowLeaderLines;
pFS->singleElement(FSNS(XML_c, XML_showLeaderLines), XML_val, ToPsz10(bShowLeaderLines));
// Export LeaderLine properties
// TODO: import all kind of LeaderLine props (not just LineColor/LineWidth)
if (bShowLeaderLines)
bool bIsPieOrDoughnut = eChartType == chart::TYPEID_PIE
|| eChartType == chart::TYPEID_DOUGHNUT;
// showLeaderLines and leaderLines are only valid inside dLbls for
// pie and doughnut charts per the OOXML schema. Writing them for
// other chart types (e.g. barChart) causes Excel to crash.
if (bIsPieOrDoughnut)
{
pFS->startElement(FSNS(XML_c, XML_leaderLines));
pFS->startElement(FSNS(XML_c, XML_spPr));
WriteOutline(xPropSet, getModel());
pFS->endElement(FSNS(XML_c, XML_spPr));
pFS->endElement(FSNS(XML_c, XML_leaderLines));
pFS->singleElement(FSNS(XML_c, XML_showLeaderLines),
XML_val, ToPsz10(bShowLeaderLines));
// Export LeaderLine properties
// TODO: import all kind of LeaderLine props (not just LineColor/LineWidth)
if (bShowLeaderLines)
{
pFS->startElement(FSNS(XML_c, XML_leaderLines));
pFS->startElement(FSNS(XML_c, XML_spPr));
WriteOutline(xPropSet, getModel());
pFS->endElement(FSNS(XML_c, XML_spPr));
pFS->endElement(FSNS(XML_c, XML_leaderLines));
}
}
// Export leader line
if( eChartType != chart::TYPEID_PIE )
else
{
// For non-pie/doughnut charts, use the c15 extension for leader lines.
pFS->startElement(FSNS(XML_c, XML_extLst));
pFS->startElement(FSNS(XML_c, XML_ext), XML_uri, "{CE6537A1-D6FC-4f65-9D91-7224C49458BB}", FSNS(XML_xmlns, XML_c15), GetFB()->getNamespaceURL(OOX_NS(c15)));
pFS->singleElement(FSNS(XML_c15, XML_showLeaderLines), XML_val, ToPsz10(bShowLeaderLines));
+2 -2
View File
@@ -1,6 +1,6 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
#
# This file is part of the Collabora Office project.
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -62,4 +62,4 @@ $(eval $(call gb_CppunitTest_use_packages,sw_xsltimport,\
filter_xslt \
))
# vim: set noet sw=4 ts=4:
# vim: set noet sw=4 ts=4:
+2 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the Collabora Office project.
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -32,4 +32,4 @@ CPPUNIT_TEST_FIXTURE(XSLTImportTest, testReplaceSpaces)
} // end of anonymous namespace
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */