diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-03-08 14:01:03 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-06-18 15:00:12 +0200 |
commit | f1d3eb7573352d9da591ccadec21f49e1a5f8cb6 (patch) | |
tree | ab8e1d172c40c9bb27859978c19d58c0394f0229 | |
parent | d03a76d0fa4c2fa5f9ecdf3ea36e257587f2c333 (diff) |
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.kaganski@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/74277
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | sc/qa/unit/data/ods/pivot-table-str-and-err-in-data.ods | bin | 0 -> 9540 bytes | |||
-rw-r--r-- | sc/qa/unit/pivottable_filters_test.cxx | 29 | ||||
-rw-r--r-- | sc/source/filter/excel/xepivotxml.cxx | 7 |
3 files changed, 34 insertions, 2 deletions
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 Binary files differnew file mode 100644 index 000000000000..9c58dc8958ae --- /dev/null +++ b/sc/qa/unit/data/ods/pivot-table-str-and-err-in-data.ods diff --git a/sc/qa/unit/pivottable_filters_test.cxx b/sc/qa/unit/pivottable_filters_test.cxx index c2546bc29cb7..a476e0d7b450 100644 --- a/sc/qa/unit/pivottable_filters_test.cxx +++ b/sc/qa/unit/pivottable_filters_test.cxx @@ -88,6 +88,7 @@ public: void testPivotTableDuplicateFields(); void testTdf112106(); void testTdf123923(); + void testTdf123939(); CPPUNIT_TEST_SUITE(ScPivotTableFiltersTest); @@ -130,6 +131,7 @@ public: CPPUNIT_TEST(testPivotTableDuplicateFields); CPPUNIT_TEST(testTdf112106); CPPUNIT_TEST(testTdf123923); + CPPUNIT_TEST(testTdf123939); CPPUNIT_TEST_SUITE_END(); @@ -2414,6 +2416,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 611078fa4ec1..41fa2161f9c2 100644 --- a/sc/source/filter/excel/xepivotxml.cxx +++ b/sc/source/filter/excel/xepivotxml.cxx @@ -266,6 +266,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) { @@ -291,8 +294,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); |