summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-05-02 19:44:47 +0300
committerAndras Timar <andras.timar@collabora.com>2019-05-03 15:07:43 +0200
commitad241543455424b9b492b357dabba27aab85c0b9 (patch)
tree2a572ce3ac53e20230eb261c70e08f6f2f6e3d02 /sc
parentd93eb86b01fcc4b2e7a63457a193b8848be9e1cf (diff)
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.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/71696 Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/data/ods/pivottable_fieldInRowsAndData.odsbin0 -> 9815 bytes
-rw-r--r--sc/qa/unit/pivottable_filters_test.cxx19
-rw-r--r--sc/source/filter/excel/xepivotxml.cxx16
3 files changed, 35 insertions, 0 deletions
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
--- /dev/null
+++ b/sc/qa/unit/data/ods/pivottable_fieldInRowsAndData.ods
Binary files differ
diff --git a/sc/qa/unit/pivottable_filters_test.cxx b/sc/qa/unit/pivottable_filters_test.cxx
index 065ad71b4e55..30969db5f039 100644
--- a/sc/qa/unit/pivottable_filters_test.cxx
+++ b/sc/qa/unit/pivottable_filters_test.cxx
@@ -96,6 +96,7 @@ public:
void testTdf124883();
void testTdf125046();
void testTdf125055();
+ void testTdf125086();
CPPUNIT_TEST_SUITE(ScPivotTableFiltersTest);
@@ -146,6 +147,7 @@ public:
CPPUNIT_TEST(testTdf124883);
CPPUNIT_TEST(testTdf125046);
CPPUNIT_TEST(testTdf125055);
+ CPPUNIT_TEST(testTdf125086);
CPPUNIT_TEST_SUITE_END();
@@ -2696,6 +2698,23 @@ 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());
+
+ std::shared_ptr<utl::TempFile> pXPathFile
+ = ScBootstrapFixture::exportTo(xDocSh.get(), FORMAT_XLSX);
+ xDocSh->DoClose();
+
+ xmlDocPtr pDoc
+ = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/pivotTables/pivotTable1.xml");
+ 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 e0a6bc84870c..752d971cfd25 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -1012,8 +1012,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_showAll, ToPsz10(false));
long nSubTotalCount = pDim->GetSubTotalsCount();