include/oox/export/chartexport.hxx |    7 ++
 oox/source/export/chartexport.cxx  |  115 +++++++++++++------------------------
 2 files changed, 49 insertions(+), 73 deletions(-)

New commits:
commit 0a8060e6d5cf7a7f1ce4b54c6019bb56995e57f6
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Nov 5 08:33:03 2025 +0200
Commit:     Michael Stahl <[email protected]>
CommitDate: Wed Nov 5 15:35:09 2025 +0100

    mso-test: order of c:numFmt element in chart.xml
    
    This is using the test document from tdf121279-1.odt.
    When importing and exporting to XLSX, the order of elements is wrong
    according to officeotron.
    Move some code around in ChartExport to get that right.
    
    Change-Id: Id09328520c05ebb35074b4bb451d08572a9c831e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193439
    Reviewed-by: Michael Stahl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/include/oox/export/chartexport.hxx 
b/include/oox/export/chartexport.hxx
index 348af941c88a..b4be727e5365 100644
--- a/include/oox/export/chartexport.hxx
+++ b/include/oox/export/chartexport.hxx
@@ -71,6 +71,8 @@ namespace core {
 
 namespace oox::drawingml {
 
+struct LabelPlacementParam;
+
 enum AxesType
 {
     AXIS_PRIMARY_X = 1,
@@ -283,6 +285,11 @@ private:
 
     OUString getNumberFormatCode(sal_Int32 nKey) const;
 
+    void writeLabelProperties(
+        const css::uno::Reference<css::beans::XPropertySet>& xPropSet, const 
LabelPlacementParam& rLabelParam,
+        sal_Int32 nLabelIndex, DataLabelsRange& rDLblsRange,
+        bool bIsChartex);
+
 public:
 
     OOX_DLLPUBLIC ChartExport( sal_Int32 nXmlNamespace, 
::sax_fastparser::FSHelperPtr pFS, css::uno::Reference< css::frame::XModel > 
const & xModel,
diff --git a/oox/source/export/chartexport.cxx 
b/oox/source/export/chartexport.cxx
index 6d6099f4134d..30dda3e7792e 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -4699,8 +4699,6 @@ void ChartExport::exportOneAxis_chartex(
     pFS->endElement( FSNS( XML_cx, XML_axis ) );
 }
 
-namespace {
-
 struct LabelPlacementParam
 {
     bool mbExport;
@@ -4727,6 +4725,8 @@ struct LabelPlacementParam
     {}
 };
 
+namespace {
+
 const char* toOOXMLPlacement( sal_Int32 nPlacement )
 {
     switch (nPlacement)
@@ -4862,7 +4862,9 @@ void writeCustomLabel( const FSHelperPtr& pFS, 
ChartExport* pChartExport,
     pFS->endElement(FSNS(XML_c, XML_tx));
 }
 
-void writeLabelProperties( const FSHelperPtr& pFS, ChartExport* pChartExport,
+}
+
+void ChartExport::writeLabelProperties(
     const uno::Reference<beans::XPropertySet>& xPropSet, const 
LabelPlacementParam& rLabelParam,
     sal_Int32 nLabelIndex, DataLabelsRange& rDLblsRange,
     bool bIsChartex)
@@ -4870,6 +4872,8 @@ void writeLabelProperties( const FSHelperPtr& pFS, 
ChartExport* pChartExport,
     if (!xPropSet.is())
         return;
 
+    FSHelperPtr pFS = GetFS();
+
     const sal_Int32 nChartNS = bIsChartex ? XML_cx : XML_c;
 
     chart2::DataPointLabel aLabel;
@@ -4878,12 +4882,38 @@ void writeLabelProperties( const FSHelperPtr& pFS, 
ChartExport* pChartExport,
     sal_Int32 nLabelBorderColor = 0x00FFFFFF;
     sal_Int32 nLabelFillColor = -1;
 
-    xPropSet->getPropertyValue(u"Label"_ustr) >>= aLabel;
     xPropSet->getPropertyValue(u"CustomLabelFields"_ustr) >>= 
aCustomLabelFields;
     xPropSet->getPropertyValue(u"LabelBorderWidth"_ustr) >>= nLabelBorderWidth;
     xPropSet->getPropertyValue(u"LabelBorderColor"_ustr) >>= nLabelBorderColor;
     xPropSet->getPropertyValue(u"LabelFillColor"_ustr) >>= nLabelFillColor;
 
+    if (aCustomLabelFields.hasElements())
+        writeCustomLabel(pFS, this, aCustomLabelFields, nLabelIndex, 
rDLblsRange); // c:tx
+
+    bool bLinkedNumFmt = false;
+    if( GetProperty(xPropSet, u"LinkNumberFormatToSource"_ustr) )
+        mAny >>= bLinkedNumFmt;
+
+    bool bLabelIsNumberFormat = true;
+    if( xPropSet->getPropertyValue(u"Label"_ustr) >>= aLabel )
+        bLabelIsNumberFormat = aLabel.ShowNumber;
+
+    if (GetProperty(xPropSet, bLabelIsNumberFormat ? u"NumberFormat"_ustr : 
u"PercentageNumberFormat"_ustr))
+    {
+        sal_Int32 nKey = 0;
+        mAny >>= nKey;
+
+        OUString aNumberFormatString = getNumberFormatCode(nKey);
+
+        if (bIsChartex) {
+            pFS->singleElement(FSNS(XML_cx, XML_numFmt), XML_formatCode, 
aNumberFormatString,
+                               XML_sourceLinked, ToPsz10(bLinkedNumFmt));
+        } else {
+            pFS->singleElement(FSNS(XML_c, XML_numFmt), XML_formatCode, 
aNumberFormatString,
+                               XML_sourceLinked, ToPsz10(bLinkedNumFmt));
+        }
+    }
+
     if (nLabelBorderWidth > 0 || nLabelFillColor != -1)
     {
         pFS->startElement(FSNS(nChartNS, XML_spPr));
@@ -4892,9 +4922,9 @@ void writeLabelProperties( const FSHelperPtr& pFS, 
ChartExport* pChartExport,
         {
             ::Color nColor(ColorTransparency, nLabelFillColor);
             if (nColor.IsTransparent())
-                pChartExport->WriteSolidFill(nColor, nColor.GetAlpha());
+                WriteSolidFill(nColor, nColor.GetAlpha());
             else
-                pChartExport->WriteSolidFill(nColor);
+                WriteSolidFill(nColor);
         }
 
         if (nLabelBorderWidth > 0)
@@ -4906,9 +4936,9 @@ void writeLabelProperties( const FSHelperPtr& pFS, 
ChartExport* pChartExport,
             {
                 ::Color nColor(ColorTransparency, nLabelBorderColor);
                 if (nColor.IsTransparent())
-                    pChartExport->WriteSolidFill(nColor, nColor.GetAlpha());
+                    WriteSolidFill(nColor, nColor.GetAlpha());
                 else
-                    pChartExport->WriteSolidFill(nColor);
+                    WriteSolidFill(nColor);
             }
 
             pFS->endElement(FSNS(XML_a, XML_ln));
@@ -4917,10 +4947,7 @@ void writeLabelProperties( const FSHelperPtr& pFS, 
ChartExport* pChartExport,
         pFS->endElement(FSNS(nChartNS, XML_spPr));
     }
 
-    pChartExport->exportTextProps(xPropSet, bIsChartex);
-
-    if (aCustomLabelFields.hasElements())
-        writeCustomLabel(pFS, pChartExport, aCustomLabelFields, nLabelIndex, 
rDLblsRange);
+    exportTextProps(xPropSet, bIsChartex); // c:txPr
 
     if (!bIsChartex) {
         // In chartex label position is an attribute of cx:dataLabel
@@ -4959,7 +4986,7 @@ void writeLabelProperties( const FSHelperPtr& pFS, 
ChartExport* pChartExport,
         // TODO: is the following correct for chartex?
         pFS->startElement(FSNS(nChartNS, XML_ext), XML_uri,
             "{CE6537A1-D6FC-4f65-9D91-7224C49458BB}", FSNS(XML_xmlns, XML_c15),
-            pChartExport->GetFB()->getNamespaceURL(OOX_NS(c15)));
+            GetFB()->getNamespaceURL(OOX_NS(c15)));
 
         pFS->singleElement(FSNS(XML_c15, XML_showDataLabelsRange), XML_val, 
"1");
 
@@ -4968,8 +4995,6 @@ void writeLabelProperties( const FSHelperPtr& pFS, 
ChartExport* pChartExport,
     }
 }
 
-}
-
 void ChartExport::exportDataLabels(
     const uno::Reference<chart2::XDataSeries> & xSeries, sal_Int32 
nSeriesLength, sal_Int32 eChartType,
     DataLabelsRange& rDLblsRange,
@@ -5096,69 +5121,13 @@ void ChartExport::exportDataLabels(
             }
         }
 
-        bool bLinkedNumFmt = false;
-        if( GetProperty(xLabelPropSet, u"LinkNumberFormatToSource"_ustr) )
-            mAny >>= bLinkedNumFmt;
-
-        chart2::DataPointLabel aLabel;
-        bool bLabelIsNumberFormat = true;
-        if( xLabelPropSet->getPropertyValue(u"Label"_ustr) >>= aLabel )
-            bLabelIsNumberFormat = aLabel.ShowNumber;
-        else
-            bLabelIsNumberFormat = true;
-
-        if (GetProperty(xLabelPropSet, bLabelIsNumberFormat ? 
u"NumberFormat"_ustr : u"PercentageNumberFormat"_ustr))
-        {
-            sal_Int32 nKey = 0;
-            mAny >>= nKey;
-
-            OUString aNumberFormatString = getNumberFormatCode(nKey);
-
-            if (bIsChartex) {
-                pFS->singleElement(FSNS(XML_cx, XML_numFmt), XML_formatCode, 
aNumberFormatString,
-                                   XML_sourceLinked, ToPsz10(bLinkedNumFmt));
-            } else {
-                pFS->singleElement(FSNS(XML_c, XML_numFmt), XML_formatCode, 
aNumberFormatString,
-                                   XML_sourceLinked, ToPsz10(bLinkedNumFmt));
-            }
-        }
-
         // Individual label property that overwrites the baseline.
-        writeLabelProperties(pFS, this, xLabelPropSet, aParam, nIdx,
-                rDLblsRange, bIsChartex);
+        writeLabelProperties(xLabelPropSet, aParam, nIdx, rDLblsRange, 
bIsChartex);
         pFS->endElement(FSNS(XML_c, XML_dLbl));
     }
 
-    bool bLinkedNumFmt = true;
-    if (GetProperty(xPropSet, u"LinkNumberFormatToSource"_ustr))
-        mAny >>= bLinkedNumFmt;
-
-    chart2::DataPointLabel aLabel;
-    bool bLabelIsNumberFormat = true;
-    if( xPropSet->getPropertyValue(u"Label"_ustr) >>= aLabel )
-        bLabelIsNumberFormat = aLabel.ShowNumber;
-
-    if (GetProperty(xPropSet, bLabelIsNumberFormat ? u"NumberFormat"_ustr : 
u"PercentageNumberFormat"_ustr))
-    {
-        sal_Int32 nKey = 0;
-        mAny >>= nKey;
-
-        OUString aNumberFormatString = getNumberFormatCode(nKey);
-
-        if (bIsChartex) {
-            pFS->singleElement(FSNS(XML_cx, XML_numFmt),
-                XML_formatCode, aNumberFormatString,
-                XML_sourceLinked, ToPsz10(bLinkedNumFmt));
-        } else {
-            pFS->singleElement(FSNS(XML_c, XML_numFmt),
-                XML_formatCode, aNumberFormatString,
-                XML_sourceLinked, ToPsz10(bLinkedNumFmt));
-        }
-    }
-
     // Baseline label properties for all labels.
-    writeLabelProperties(pFS, this, xPropSet, aParam, -1, rDLblsRange,
-            bIsChartex);
+    writeLabelProperties(xPropSet, aParam, -1, rDLblsRange, bIsChartex);
 
     if (!bIsChartex) {
         bool bShowLeaderLines = false;

Reply via email to