oox/source/export/chartexport.cxx      |   39 +++++++++++++++++++++++----------
 sc/qa/unit/data/xlsx/tdf165503.xlsx    |binary
 sc/qa/unit/subsequent_export_test4.cxx |   32 +++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 11 deletions(-)

New commits:
commit c51904d5672f4d08d90232070ef37fbdce76357f
Author:     Aron Budea <[email protected]>
AuthorDate: Sat Mar 1 01:30:49 2025 +1030
Commit:     Aron Budea <[email protected]>
CommitDate: Thu Mar 6 09:06:31 2025 +0100

    tdf#165503 oox: save numerical date categories into numerical cache
    
    f547cf17a179ebd7de5c2b4dd2d00d0027a25429 switched
    saving date categories from text to numeric, but
    the values were still formatted text.
    Excel considered these files corrupted.
    
    Switch to saving actual numeric values.
    
    Change-Id: I1f77a87fd66d6f8fde4987f110e37ed55711bdf3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182364
    Tested-by: Jenkins
    Reviewed-by: Dennis Francis <[email protected]>
    (cherry picked from commit 9d3fba976012b65e740c024e753f034600ce2852)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182414
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/oox/source/export/chartexport.cxx 
b/oox/source/export/chartexport.cxx
index c80e8c1ba688..d01bbb388721 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -2912,25 +2912,42 @@ void ChartExport::exportSeriesCategory( const 
Reference< chart2::data::XDataSequ
         pFS->writeEscaped(aCellRange);
         pFS->endElement(FSNS(XML_c, XML_f));
 
-        ::std::vector< OUString > aCategories;
-        lcl_fillCategoriesIntoStringVector(xValueSeq, aCategories);
-        sal_Int32 ptCount = aCategories.size();
         pFS->startElement(FSNS(XML_c, bWriteDateCategories ? XML_numCache : 
XML_strCache));
         if (bWriteDateCategories)
         {
             pFS->startElement(FSNS(XML_c, XML_formatCode));
             pFS->writeEscaped(aNumberFormatString);
             pFS->endElement(FSNS(XML_c, XML_formatCode));
-        }
 
-        pFS->singleElement(FSNS(XML_c, XML_ptCount), XML_val, 
OString::number(ptCount));
-        for (sal_Int32 i = 0; i < ptCount; i++)
+            std::vector<double> aDateCategories = 
lcl_getAllValuesFromSequence(xValueSeq);
+            const sal_Int32 ptCount = aDateCategories.size();
+            pFS->singleElement(FSNS(XML_c, XML_ptCount), XML_val, 
OString::number(ptCount));
+            for (sal_Int32 i = 0; i < ptCount; i++)
+            {
+                if (!std::isnan(aDateCategories[i]))
+                {
+                    pFS->startElement(FSNS(XML_c, XML_pt), XML_idx, 
OString::number(i));
+                    pFS->startElement(FSNS(XML_c, XML_v));
+                    pFS->write(OString::number(aDateCategories[i]));
+                    pFS->endElement(FSNS(XML_c, XML_v));
+                    pFS->endElement(FSNS(XML_c, XML_pt));
+                }
+            }
+        }
+        else
         {
-            pFS->startElement(FSNS(XML_c, XML_pt), XML_idx, 
OString::number(i));
-            pFS->startElement(FSNS(XML_c, XML_v));
-            pFS->writeEscaped(aCategories[i]);
-            pFS->endElement(FSNS(XML_c, XML_v));
-            pFS->endElement(FSNS(XML_c, XML_pt));
+            std::vector<OUString> aCategories;
+            lcl_fillCategoriesIntoStringVector(xValueSeq, aCategories);
+            const sal_Int32 ptCount = aCategories.size();
+            pFS->singleElement(FSNS(XML_c, XML_ptCount), XML_val, 
OString::number(ptCount));
+            for (sal_Int32 i = 0; i < ptCount; i++)
+            {
+                pFS->startElement(FSNS(XML_c, XML_pt), XML_idx, 
OString::number(i));
+                pFS->startElement(FSNS(XML_c, XML_v));
+                pFS->writeEscaped(aCategories[i]);
+                pFS->endElement(FSNS(XML_c, XML_v));
+                pFS->endElement(FSNS(XML_c, XML_pt));
+            }
         }
 
         pFS->endElement(FSNS(XML_c, bWriteDateCategories ? XML_numCache : 
XML_strCache));
diff --git a/sc/qa/unit/data/xlsx/tdf165503.xlsx 
b/sc/qa/unit/data/xlsx/tdf165503.xlsx
new file mode 100644
index 000000000000..a581c93cd9c4
Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf165503.xlsx differ
diff --git a/sc/qa/unit/subsequent_export_test4.cxx 
b/sc/qa/unit/subsequent_export_test4.cxx
index ff4bf86dc1b1..e8ca463e8441 100644
--- a/sc/qa/unit/subsequent_export_test4.cxx
+++ b/sc/qa/unit/subsequent_export_test4.cxx
@@ -1862,6 +1862,38 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf164417)
         getXPathPosition(pSheet1, 
"//x:autoFilter/x:filterColumn/x:filters"_ostr, "dateGroupItem"));
 }
 
+CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf165503)
+{
+    createScDoc("xlsx/tdf165503.xlsx");
+
+    // FIXME: Invalid content was found starting with element 'c:noMultiLvlLbl'
+    skipValidation();
+    save(u"Calc Office Open XML"_ustr);
+
+    xmlDocUniquePtr pChart1 = parseExport(u"xl/charts/chart1.xml"_ustr);
+    CPPUNIT_ASSERT(pChart1);
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 44199
+    // - Actual  : 1/3/2021
+    // The textual date output can depend on locale, but it'll differ from 
expected value either way
+    assertXPathContent(pChart1,
+                       
"/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:cat/c:numRef/"
+                       "c:numCache/c:pt[@idx=\"0\"]/c:v"_ostr,
+                       "44199");
+    // And similarly
+    assertXPathContent(pChart1,
+                       
"/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:cat/c:numRef/"
+                       "c:numCache/c:pt[@idx=\"4\"]/c:v"_ostr,
+                       "44844");
+
+    // There should be no node with idx 5 (cell is empty)
+    const int aNodes = countXPathNodes(
+        pChart1, 
"/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:cat/c:numRef/"
+                 "c:numCache/c:pt[@idx=\"5\"]"_ostr);
+    CPPUNIT_ASSERT_EQUAL(0, aNodes);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to