sc/qa/unit/data/ods/pivot-table-str-and-err-in-data.ods |binary
 sc/qa/unit/pivottable_filters_test.cxx                  |   29 ++++++++++++++++
 sc/source/filter/excel/xepivotxml.cxx                   |    7 ++-
 3 files changed, 34 insertions(+), 2 deletions(-)

New commits:
commit ebc7f46f65cb853845eae9c2f7b96f341e4b0cb4
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Mar 8 14:01:03 2019 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Mar 11 20:18:35 2019 +0100

    tdf#123939: string and error are same type for pivot cache in XLSX
    
    Change-Id: Id39d322661f7537e8999acafee655c0cc16a78c1
    Reviewed-on: https://gerrit.libreoffice.org/68911
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/69063
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/qa/unit/data/ods/pivot-table-str-and-err-in-data.ods 
b/sc/qa/unit/data/ods/pivot-table-str-and-err-in-data.ods
new file mode 100644
index 000000000000..9c58dc8958ae
Binary files /dev/null and 
b/sc/qa/unit/data/ods/pivot-table-str-and-err-in-data.ods differ
diff --git a/sc/qa/unit/pivottable_filters_test.cxx 
b/sc/qa/unit/pivottable_filters_test.cxx
index 1a046296357f..4674ebb2533f 100644
--- a/sc/qa/unit/pivottable_filters_test.cxx
+++ b/sc/qa/unit/pivottable_filters_test.cxx
@@ -85,6 +85,7 @@ public:
     void testPivotTableTabularModeXLSX();
     void testTdf112106();
     void testTdf123923();
+    void testTdf123939();
 
     CPPUNIT_TEST_SUITE(ScPivotTableFiltersTest);
 
@@ -124,6 +125,7 @@ public:
     CPPUNIT_TEST(testPivotTableTabularModeXLSX);
     CPPUNIT_TEST(testTdf112106);
     CPPUNIT_TEST(testTdf123923);
+    CPPUNIT_TEST(testTdf123939);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -2334,6 +2336,33 @@ void ScPivotTableFiltersTest::testTdf123923()
                 "v", "#REF!");
 }
 
+void ScPivotTableFiltersTest::testTdf123939()
+{
+    // tdf#123939: Excel warns on containsMixedTypes="1" if sharedItems has 
only strings and errors
+
+    ScDocShellRef xShell = loadDoc("pivot-table-str-and-err-in-data.", 
FORMAT_ODS);
+    CPPUNIT_ASSERT(xShell.is());
+
+    std::shared_ptr<utl::TempFile> pXPathFile
+        = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX);
+    xmlDocPtr pTable = XPathHelper::parseExport(pXPathFile, m_xSFactory,
+                                                
"xl/pivotCache/pivotCacheDefinition1.xml");
+    CPPUNIT_ASSERT(pTable);
+
+    assertXPathNoAttribute(pTable,
+                           
"/x:pivotCacheDefinition/x:cacheFields/x:cacheField[1]/x:sharedItems",
+                           "containsMixedTypes");
+
+    // But we must emit containsMixedTypes="1" for a mix of errors and 
non-string types!
+
+    pTable = XPathHelper::parseExport(pXPathFile, m_xSFactory,
+                                      
"xl/pivotCache/pivotCacheDefinition2.xml");
+    CPPUNIT_ASSERT(pTable);
+
+    assertXPath(pTable, 
"/x:pivotCacheDefinition/x:cacheFields/x:cacheField[1]/x:sharedItems",
+                "containsMixedTypes", "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 5d47d628cee7..2ed98873202f 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -267,6 +267,9 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( 
XclExpXmlStream& rStrm, const Entr
         for (; it != itEnd; ++it)
         {
             ScDPItemData::Type eType = it->GetType();
+            // tdf#123939 : error and string are same for cache; if both are 
present, keep only one
+            if (eType == ScDPItemData::Error)
+                eType = ScDPItemData::String;
             aDPTypes.insert(eType);
             if (eType == ScDPItemData::Value)
             {
@@ -292,8 +295,8 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( 
XclExpXmlStream& rStrm, const Entr
         std::set<ScDPItemData::Type> aDPTypesWithoutBlank = aDPTypes;
         aDPTypesWithoutBlank.erase(ScDPItemData::Empty);
 
-        bool isContainsString = 
aDPTypesWithoutBlank.find(ScDPItemData::String) != aDPTypesWithoutBlank.end() ||
-                                aDPTypesWithoutBlank.find(ScDPItemData::Error) 
!= aDPTypesWithoutBlank.end();
+        const bool isContainsString
+            = aDPTypesWithoutBlank.find(ScDPItemData::String) != 
aDPTypesWithoutBlank.end();
         bool isContainsBlank = aDPTypes.find(ScDPItemData::Empty) != 
aDPTypeEnd;
         bool isContainsNumber = !isContainsDate && 
aDPTypesWithoutBlank.find(ScDPItemData::Value) != aDPTypesWithoutBlank.end();
         bool isContainsNonDate = !(isContainsDate && 
aDPTypesWithoutBlank.size() <= 1);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to