include/oox/export/chartexport.hxx | 7 ++ oox/source/export/chartexport.cxx | 115 +++++++++++++------------------------ 2 files changed, 49 insertions(+), 73 deletions(-)
New commits: commit 732a501206bb2356e28a5fa0c27cebc43ef3b366 Author: Noel Grandin <[email protected]> AuthorDate: Wed Nov 5 08:33:03 2025 +0200 Commit: Xisco Fauli <[email protected]> CommitDate: Thu Nov 6 15:45:34 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]> (cherry picked from commit 0a8060e6d5cf7a7f1ce4b54c6019bb56995e57f6) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193481 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> Signed-off-by: Xisco Fauli <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193536 diff --git a/include/oox/export/chartexport.hxx b/include/oox/export/chartexport.hxx index 2d745d295986..8953e64889fb 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, @@ -282,6 +284,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 eba248197c22..eb06aa73e888 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -4427,8 +4427,6 @@ void ChartExport::exportOneAxis_chartex( pFS->endElement( FSNS( XML_cx, XML_axis ) ); } -namespace { - struct LabelPlacementParam { bool mbExport; @@ -4455,6 +4453,8 @@ struct LabelPlacementParam {} }; +namespace { + const char* toOOXMLPlacement( sal_Int32 nPlacement ) { switch (nPlacement) @@ -4590,7 +4590,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) @@ -4598,6 +4600,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; @@ -4606,12 +4610,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)); @@ -4620,9 +4650,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) @@ -4634,9 +4664,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)); @@ -4645,10 +4675,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 @@ -4687,7 +4714,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"); @@ -4696,8 +4723,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, @@ -4824,69 +4849,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;
