sc/qa/unit/data/ods/pivottable_fieldInRowsAndData.ods |binary
 sc/qa/unit/pivottable_filters_test.cxx                |   15 +++++++++++++++
 sc/source/filter/excel/xepivotxml.cxx                 |   16 ++++++++++++++++
 3 files changed, 31 insertions(+)

New commits:
commit 31297f32aa9a35897055b0d377af332a4bb977a1
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu May 2 19:44:47 2019 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu May 2 19:48:10 2019 +0200

    tdf#125086: Write dataField attribute for fields that also appear in Data
    
    Change-Id: Id9f8f07bfdb1060f0c3d7ed6f8526a6bfdd84eb4
    Reviewed-on: https://gerrit.libreoffice.org/71687
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/qa/unit/data/ods/pivottable_fieldInRowsAndData.ods 
b/sc/qa/unit/data/ods/pivottable_fieldInRowsAndData.ods
new file mode 100644
index 000000000000..cbb773857605
Binary files /dev/null and 
b/sc/qa/unit/data/ods/pivottable_fieldInRowsAndData.ods differ
diff --git a/sc/qa/unit/pivottable_filters_test.cxx 
b/sc/qa/unit/pivottable_filters_test.cxx
index 5df1766190cb..14fca36bae17 100644
--- a/sc/qa/unit/pivottable_filters_test.cxx
+++ b/sc/qa/unit/pivottable_filters_test.cxx
@@ -93,6 +93,7 @@ public:
     void testTdf124883();
     void testTdf125046();
     void testTdf125055();
+    void testTdf125086();
 
     CPPUNIT_TEST_SUITE(ScPivotTableFiltersTest);
 
@@ -143,6 +144,7 @@ public:
     CPPUNIT_TEST(testTdf124883);
     CPPUNIT_TEST(testTdf125046);
     CPPUNIT_TEST(testTdf125055);
+    CPPUNIT_TEST(testTdf125086);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -2684,6 +2686,19 @@ void ScPivotTableFiltersTest::testTdf125055()
                pDoc, 
"/x:pivotCacheDefinition/x:cacheFields/x:cacheField[2]/x:sharedItems", "m"));
 }
 
+void ScPivotTableFiltersTest::testTdf125086()
+{
+    ScDocShellRef xDocSh = loadDoc("pivottable_fieldInRowsAndData.", 
FORMAT_ODS);
+    CPPUNIT_ASSERT(xDocSh.is());
+
+    xmlDocPtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory,
+                                               
"xl/pivotTables/pivotTable1.xml", FORMAT_XLSX);
+    CPPUNIT_ASSERT(pDoc);
+    assertXPath(pDoc, "/x:pivotTableDefinition/x:pivotFields/x:pivotField[2]", 
"axis", "axisRow");
+    // "dataField" attribute was not written for this "axisRow" field
+    assertXPath(pDoc, "/x:pivotTableDefinition/x:pivotFields/x:pivotField[2]", 
"dataField", "1");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(ScPivotTableFiltersTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/excel/xepivotxml.cxx 
b/sc/source/filter/excel/xepivotxml.cxx
index e3ee0d7e0573..3143f3b1b04a 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -973,8 +973,24 @@ void XclExpXmlPivotTables::SavePivotTableXml( 
XclExpXmlStream& rStrm, const ScDP
                 aMemberSequence.emplace_back(nItem, true);
         }
 
+        // tdf#125086: check if this field *also* appears in Data region
+        bool bAppearsInData = false;
+        {
+            OUString aSrcName = 
ScDPUtil::getSourceDimensionName(pDim->GetName());
+            const auto it = std::find_if(
+                aDataFields.begin(), aDataFields.end(), [&aSrcName](const 
DataField& rDataField) {
+                    OUString aThisName
+                        = 
ScDPUtil::getSourceDimensionName(rDataField.mpDim->GetName());
+                    return aThisName == aSrcName;
+                });
+            if (it != aDataFields.end())
+                bAppearsInData = true;
+        }
+
         auto pAttList = sax_fastparser::FastSerializerHelper::createAttrList();
         pAttList->add(XML_axis, toOOXMLAxisType(eOrient));
+        if (bAppearsInData)
+            pAttList->add(XML_dataField, ToPsz10(true));
         pAttList->add(XML_compact, ToPsz10(false));
         pAttList->add(XML_showAll, ToPsz10(false));
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to