oox/source/export/chartexport.cxx          |   25 ++++++++++++++++++-------
 sc/qa/unit/data/xls/forum-mso-de-48440.xls |binary
 sc/qa/unit/subsequent_export_test.cxx      |   24 ++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 7 deletions(-)

New commits:
commit a26b7f57c04d954f64e206fcfbddc948b3725334
Author:     Ujjawal Kumar <[email protected]>
AuthorDate: Wed Mar 4 14:07:16 2026 +0530
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Mar 6 09:37:35 2026 +0100

    ooxml: Fix export of combined charts by reusing axes.
    
    Excel expects a maximum of 2 axis one for primary
    and the one for secondary. We have to share axes
    whenever we can.
    
    Bug document: forum-mso-de-48440.xls
    
    The above document when exported to xlsx was generating
    an extra primary axis pair for the first scatter chart.
    It rather should have shared the primary axis generated
    by the bar chart.
    
    Change-Id: I70c0abd21b8ea93afc01d2fd080299da53bf2cf7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200933
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/oox/source/export/chartexport.cxx 
b/oox/source/export/chartexport.cxx
index 9e1fd1551e02..29aea90b1fe7 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -2201,7 +2201,9 @@ void ChartExport::exportAreaChart( const Reference< 
chart2::XChartType >& xChart
         bool bPrimaryAxes = true;
         if (splitDataSeries.hasElements())
             exportSeries(xChartType, splitDataSeries, bPrimaryAxes);
-        exportAxesId(bPrimaryAxes);
+
+        bool bCheckCombinedAxes = !maAxes.empty();
+        exportAxesId(bPrimaryAxes, bCheckCombinedAxes);
 
         pFS->endElement(FSNS(XML_c, nTypeId));
     }
@@ -2304,7 +2306,8 @@ void ChartExport::exportBarChart(const Reference< 
chart2::XChartType >& xChartTy
             }
         }
 
-        exportAxesId(bPrimaryAxes);
+        bool bCheckCombinedAxes = !maAxes.empty();
+        exportAxesId(bPrimaryAxes, bCheckCombinedAxes);
 
         pFS->endElement(FSNS(XML_c, nTypeId));
     }
@@ -2329,7 +2332,8 @@ void ChartExport::exportBubbleChart( const Reference< 
chart2::XChartType >& xCha
         if (splitDataSeries.hasElements())
             exportSeries(xChartType, splitDataSeries, bPrimaryAxes);
 
-        exportAxesId(bPrimaryAxes);
+        bool bCheckCombinedAxes = !maAxes.empty();
+        exportAxesId(bPrimaryAxes, bCheckCombinedAxes);
 
         pFS->endElement(FSNS(XML_c, XML_bubbleChart));
     }
@@ -2493,7 +2497,9 @@ void ChartExport::exportRadarChart( const Reference< 
chart2::XChartType >& xChar
     exportVaryColors(xChartType);
     bool bPrimaryAxes = true;
     exportAllSeries(xChartType, bPrimaryAxes);
-    exportAxesId(bPrimaryAxes);
+
+    bool bCheckCombinedAxes = !maAxes.empty();
+    exportAxesId(bPrimaryAxes, bCheckCombinedAxes);
 
     pFS->endElement( FSNS( XML_c, XML_radarChart ) );
 }
@@ -2523,7 +2529,9 @@ void ChartExport::exportScatterChartSeries( const 
Reference< chart2::XChartType
     bool bPrimaryAxes = true;
     if (pSeries)
         exportSeries(xChartType, *pSeries, bPrimaryAxes);
-    exportAxesId(bPrimaryAxes);
+
+    bool bCheckCombinedAxes = !maAxes.empty();
+    exportAxesId(bPrimaryAxes, bCheckCombinedAxes);
 
     pFS->endElement( FSNS( XML_c, XML_scatterChart ) );
 }
@@ -2571,7 +2579,8 @@ void ChartExport::exportStockChart( const Reference< 
chart2::XChartType >& xChar
             exportUpDownBars(xChartType);
         }
 
-        exportAxesId(bPrimaryAxes);
+        bool bCheckCombinedAxes = !maAxes.empty();
+        exportAxesId(bPrimaryAxes, bCheckCombinedAxes);
 
         pFS->endElement(FSNS(XML_c, XML_stockChart));
     }
@@ -2646,7 +2655,9 @@ void ChartExport::exportSurfaceChart( const Reference< 
chart2::XChartType >& xCh
     exportVaryColors(xChartType);
     bool bPrimaryAxes = true;
     exportAllSeries(xChartType, bPrimaryAxes);
-    exportAxesId(bPrimaryAxes);
+
+    bool bCheckCombinedAxes = !maAxes.empty();
+    exportAxesId(bPrimaryAxes, bCheckCombinedAxes);
 
     pFS->endElement( FSNS( XML_c, nTypeId ) );
 }
diff --git a/sc/qa/unit/data/xls/forum-mso-de-48440.xls 
b/sc/qa/unit/data/xls/forum-mso-de-48440.xls
new file mode 100644
index 000000000000..fc480793a0ff
Binary files /dev/null and b/sc/qa/unit/data/xls/forum-mso-de-48440.xls differ
diff --git a/sc/qa/unit/subsequent_export_test.cxx 
b/sc/qa/unit/subsequent_export_test.cxx
index 6cf4198006ee..8dbe53c428f9 100644
--- a/sc/qa/unit/subsequent_export_test.cxx
+++ b/sc/qa/unit/subsequent_export_test.cxx
@@ -2263,6 +2263,30 @@ CPPUNIT_TEST_FIXTURE(ScExportTest, 
testCombinedChartAxesCount)
     assertXPath(pChart, "/c:chartSpace/c:chart/c:plotArea/c:valAx", 2);
 }
 
+CPPUNIT_TEST_FIXTURE(ScExportTest, testCombinedChartsAxesSharing)
+{
+    createScDoc("xls/forum-mso-de-48440.xls");
+    save(TestFilter::XLSX);
+
+    xmlDocUniquePtr pChart = parseExport(u"xl/charts/chart3.xml"_ustr);
+    CPPUNIT_ASSERT(pChart);
+
+    assertXPath(pChart, "/c:chartSpace/c:chart/c:plotArea/c:catAx", 1);
+    assertXPath(pChart, "/c:chartSpace/c:chart/c:plotArea/c:valAx", 3);
+
+    OUString barChartAxis1
+        = getXPath(pChart, 
"/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[1]", "val");
+    OUString scatterChart1Axis1
+        = getXPath(pChart, 
"/c:chartSpace/c:chart/c:plotArea/c:scatterChart[1]/c:axId[1]", "val");
+    CPPUNIT_ASSERT_EQUAL(barChartAxis1, scatterChart1Axis1);
+
+    OUString barChartAxis2
+        = getXPath(pChart, 
"/c:chartSpace/c:chart/c:plotArea/c:barChart/c:axId[2]", "val");
+    OUString scatterChart1Axis2
+        = getXPath(pChart, 
"/c:chartSpace/c:chart/c:plotArea/c:scatterChart[1]/c:axId[2]", "val");
+    CPPUNIT_ASSERT_EQUAL(barChartAxis2, scatterChart1Axis2);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to