oox/source/drawingml/chart/datasourcecontext.cxx |    1 
 oox/source/drawingml/chart/seriescontext.cxx     |    1 
 oox/source/export/chartexport.cxx                |   41 +++++++++++++++++++++--
 3 files changed, 40 insertions(+), 3 deletions(-)

New commits:
commit 2cf51173f3e2915065a355058ef0c5fe15cc89cb
Author:     Kurt Nordback <[email protected]>
AuthorDate: Mon Dec 29 13:36:25 2025 -0700
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Fri Jan 9 07:21:55 2026 +0100

    tdf#165742 Step 5.2: Fix some round-trip failures
    
    Fix formula references in chartex data elements, and put in
    special handling for sunburst and treemap formula references
    (these two types, at least, require category references as well
    as value references).
    
    Change-Id: Id9a2b1c54559f0f19a39d3635ff314e5894a9f0f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196316
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/oox/source/drawingml/chart/datasourcecontext.cxx 
b/oox/source/drawingml/chart/datasourcecontext.cxx
index d27b715dbbc7..2532b6ad866d 100644
--- a/oox/source/drawingml/chart/datasourcecontext.cxx
+++ b/oox/source/drawingml/chart/datasourcecontext.cxx
@@ -298,6 +298,7 @@ void StringSequenceContext::onCharacters( const OUString& 
rChars )
     switch( getCurrentElement() )
     {
         case C_TOKEN( f ):
+        case CX_TOKEN( f ):
             mrModel.maFormula = rChars;
         break;
         case C15_TOKEN( f ):
diff --git a/oox/source/drawingml/chart/seriescontext.cxx 
b/oox/source/drawingml/chart/seriescontext.cxx
index c913aa31928e..ba0876e2222b 100644
--- a/oox/source/drawingml/chart/seriescontext.cxx
+++ b/oox/source/drawingml/chart/seriescontext.cxx
@@ -790,6 +790,7 @@ ContextHandlerRef ChartexSeriesContext::onCreateContext( 
sal_Int32 nElement, con
                     return new DataLabelsContext( *this, 
mrModel.mxLabels.create(false) );
                 case CX_TOKEN( dataId ):
                     mrModel.mnDataId = rAttribs.getInteger(XML_val, -1);
+                    mrModel.mnIndex = rAttribs.getInteger( XML_val, -1 );
                     return nullptr;
                 case CX_TOKEN( layoutPr ):
                     // This looks complicated. TODO
diff --git a/oox/source/export/chartexport.cxx 
b/oox/source/export/chartexport.cxx
index 5609ecc3c52b..2c695a94d7ca 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -1583,14 +1583,49 @@ void ChartExport::exportData_chartex( [[maybe_unused]] 
const Reference< css::cha
                     // The data id needs to agree with the id in 
exportSeries(). See DATA_ID_COMMENT
                     pFS->startElement(FSNS(XML_cx, XML_data), XML_id, 
OUString::number(nSeriesIndex));
 
-                    // .xlsx chartex files seem to have this magical 
"_xlchart.v2.0" string,
+                    // .xlsx chartex files seem to have this magical 
"_xlchart..." string,
                     // and no explicit data, while .docx and .pptx contain the 
literal data,
                     // as well as a ../embeddings file (which LO doesn't seem 
to produce).
                     // But there's probably a smarter way to determine which 
pathway to take
                     // than based on document type.
                     if (GetDocumentType() == DOCUMENT_XLSX) {
                         // Just hard-coding this for now
-                        pFS->startElement(FSNS(XML_cx, XML_numDim), XML_type, 
"val");
+
+                        sal_Int32 nSuffixVal = nSeriesIndex;
+
+                        // Output category data formula for some chart types.
+                        // (This is completely hacky)
+                        if (eChartType ==  chart::TYPEID_SUNBURST ||
+                                eChartType == chart::TYPEID_TREEMAP) {
+                            pFS->startElement(FSNS(XML_cx, XML_strDim), 
XML_type, "cat");
+                            pFS->startElement(FSNS(XML_cx, XML_f));
+
+                            std::string sFormulaId = "_xlchart.v1.";
+                            sFormulaId.append(std::to_string(nSuffixVal));
+
+                            pFS->writeEscaped(sFormulaId);
+
+                            pFS->endElement(FSNS(XML_cx, XML_f));
+                            pFS->endElement(FSNS(XML_cx, XML_strDim));
+
+                            ++nSuffixVal;
+                        }
+
+                        // Set the ST_NumericDimensionType. For some (stupid?)
+                        // reason, MSO requires the value data for sunburst and
+                        // treemap to be type "size", while for most other 
chart
+                        // types it's of type "val".
+                        std::string sNumDimType;
+                        if (eChartType ==  chart::TYPEID_SUNBURST ||
+                                eChartType == chart::TYPEID_TREEMAP) {
+                            sNumDimType = "size";
+                        } else {
+                            sNumDimType = "val";
+                        }
+
+                        // Now output value data formula
+                        pFS->startElement(FSNS(XML_cx, XML_numDim), XML_type,
+                                sNumDimType.c_str());
                         pFS->startElement(FSNS(XML_cx, XML_f));
 
                         // Set the formula value based on the chart type. This
@@ -1621,7 +1656,7 @@ void ChartExport::exportData_chartex( [[maybe_unused]] 
const Reference< css::cha
                         // Append the id value, which seems (?) to be what
                         // follows the period in the string. E.g., for id=2 we
                         // might end up with "_xlchart.v1.2"
-                        sFormulaId.append(std::to_string(nSeriesIndex));
+                        sFormulaId.append(std::to_string(nSuffixVal));
 
                         pFS->writeEscaped(sFormulaId);
 

Reply via email to