From d828577bcd522eaa57e40f889c8f3ae563ea1a75 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Thu, 24 Aug 2017 13:18:44 +0300 Subject: [PATCH] tdf#89139: list all items in pivot table definition, incl. hidden Change-Id: I14ce935185a6e0e3739fcf01fdefa031d814e821 Reviewed-on: https://gerrit.libreoffice.org/41509 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- .../unit/data/xlsx/tdf89139_pivot_table.xlsx | Bin 0 -> 15483 bytes sc/qa/unit/subsequent_export-test.cxx | 18 +++++++ sc/source/filter/excel/xepivotxml.cxx | 46 +++++++++++++----- 3 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 sc/qa/unit/data/xlsx/tdf89139_pivot_table.xlsx diff --git a/sc/qa/unit/data/xlsx/tdf89139_pivot_table.xlsx b/sc/qa/unit/data/xlsx/tdf89139_pivot_table.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..83d5b3dc15567737bf4571a5296703a9a8d5e1f2 GIT binary patch literal 15483 zcmeHuWmFw&lP(h6U4y&3ySsaEcekLy-Q6L&f%PyJNNIM zuUTs^diSnpb=O-}Z`D)P3euo&P=UaKAc25@2!W=Q3R+5mfq*n2fPhedAVJ;<+u1ss z*gET}ytg-T(xG#=u_pNV281FP2n6u^e;@ygHPELzEZ56`*hYMg5La33u<-%W@~htf z5|tKTR}_2HOkYErw8cwy)H^&O3+ZVhy7vp*%&pl+@V3b=Ni+nx4s0lU7J4N5PDN2! zCYvS~GRZ5xe$`op)o8)e_)$V zmU>l~63{<9NvCm3>wgx93&w;$$yKOCBfXV=Zc}4oRU>IU^oCOpcAO>T>nH^T^Kzd&DDUTk?LFx8P*%MjJhAO)=S)_J7zTF-cy z^_V5fZQlS=WUz5Q2yaQcQ_8SZM>9hX7rVS$fHSQujiMH{5x?{4dQ665|I&S25X-&j zdNdc^vt$T6jCf->Eqy26!cc#D|EB>ud7Oc4sd_4};AOBVUvfL)Dsdc#A|R~F5a}=m zPslhmwDoG=Y{-_FW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ent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index 10031f9f5b86..2ba55186cd30 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -115,6 +115,7 @@ public: void testCellNoteExportXLS(); void testFormatExportODS(); + void testPivotTableExportXLSX(); void testPivotExportXLSX(); void testCommentExportXLSX(); #if HAVE_MORE_FONTS @@ -227,6 +228,7 @@ public: CPPUNIT_TEST(testCellNoteExportXLS); CPPUNIT_TEST(testFormatExportODS); + CPPUNIT_TEST(testPivotTableExportXLSX); CPPUNIT_TEST(testPivotExportXLSX); CPPUNIT_TEST(testCommentExportXLSX); #if HAVE_MORE_FONTS @@ -563,6 +565,22 @@ void ScExportTest::testFormatExportODS() xDocSh->DoClose(); } +void ScExportTest::testPivotTableExportXLSX() +{ + // tdf#89139: pivot table definition needs to list items, including hidden + + ScDocShellRef xShell = loadDoc("tdf89139_pivot_table.", FORMAT_XLSX); + CPPUNIT_ASSERT(xShell.is()); + + std::shared_ptr pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + xmlDocPtr pTable = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/pivotTables/pivotTable1.xml"); + CPPUNIT_ASSERT(pTable); + + assertXPath(pTable, "/x:pivotTableDefinition/x:pivotFields/x:pivotField[3]/x:items", "count", "4"); + assertXPath(pTable, "/x:pivotTableDefinition/x:pivotFields/x:pivotField[3]/x:items/x:item", 4); + assertXPath(pTable, "/x:pivotTableDefinition/x:pivotFields/x:pivotField[3]/x:items/x:item[3]", "h", "1"); +} + void ScExportTest::testPivotExportXLSX() { // tdf#89139 FILESAVE xlsx pivot table corrupted after save with LO and re-open with MS Office diff --git a/sc/source/filter/excel/xepivotxml.cxx b/sc/source/filter/excel/xepivotxml.cxx index c5872e24da4a..e3283ef87c2d 100644 --- a/sc/source/filter/excel/xepivotxml.cxx +++ b/sc/source/filter/excel/xepivotxml.cxx @@ -701,24 +701,35 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP } // Dump field items. - css::uno::Sequence aMemberNames; + std::vector aMembers; { // We need to get the members in actual order, getting which requires non-const reference here auto& dpo = const_cast(rDPObj); - dpo.GetMemberNames(i, aMemberNames); + dpo.GetMembers(i, dpo.GetUsedHierarchy(i), aMembers); } const ScDPCache::ScDPItemDataVec& rCacheFieldItems = rCache.GetDimMemberValues(i); - std::vector aMemberSequence; - for (const OUString& sMemberName : aMemberNames) + const auto iCacheFieldItems_begin = rCacheFieldItems.begin(), iCacheFieldItems_end = rCacheFieldItems.end(); + // The pair contains the member index in cache and if it is hidden + std::vector< std::pair > aMemberSequence; + std::set aUsedCachePositions; + for (const auto & rMember : aMembers) { - auto it = std::find_if(rCacheFieldItems.begin(), rCacheFieldItems.end(), - [&sMemberName](const ScDPItemData& arg) -> bool { return arg.GetString() == sMemberName; }); - if (it != rCacheFieldItems.end()) + auto it = std::find_if(iCacheFieldItems_begin, iCacheFieldItems_end, + [&rMember](const ScDPItemData& arg) -> bool { return arg.GetString() == rMember.maName; }); + if (it != iCacheFieldItems_end) { - aMemberSequence.push_back(it - rCacheFieldItems.begin()); + size_t nCachePos = it - iCacheFieldItems_begin; + aMemberSequence.push_back(std::make_pair(nCachePos, !rMember.mbVisible)); + aUsedCachePositions.insert(nCachePos); } } + // Now add all remaining cache items as hidden + for (size_t nItem = 0; nItem < rCacheFieldItems.size(); ++nItem) + { + if (aUsedCachePositions.find(nItem) == aUsedCachePositions.end()) + aMemberSequence.push_back(std::make_pair(nItem, true)); + } auto pAttList = sax_fastparser::FastSerializerHelper::createAttrList(); pAttList->add(XML_axis, toOOXMLAxisType(eOrient)); @@ -726,14 +737,20 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP long nSubTotalCount = pDim->GetSubTotalsCount(); std::vector aSubtotalSequence; + bool bHasDefaultSubtotal = false; for (long nSubTotal = 0; nSubTotal < nSubTotalCount; ++nSubTotal) { ScGeneralFunction eFunc = pDim->GetSubTotalFunc(nSubTotal); aSubtotalSequence.push_back(GetSubtotalFuncName(eFunc)); sal_Int32 nAttToken = GetSubtotalAttrToken(eFunc); - if (!pAttList->hasAttribute(nAttToken)) + if (nAttToken == XML_defaultSubtotal) + bHasDefaultSubtotal = true; + else if (!pAttList->hasAttribute(nAttToken)) pAttList->add(nAttToken, ToPsz10(true)); } + // XML_defaultSubtotal is true by default; only write it if it's false + if (!bHasDefaultSubtotal) + pAttList->add(XML_defaultSubtotal, ToPsz10(false)); sax_fastparser::XFastAttributeListRef xAttributeList(pAttList); pPivotStrm->startElement(XML_pivotField, xAttributeList); @@ -742,11 +759,14 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP XML_count, OString::number(static_cast(aMemberSequence.size() + aSubtotalSequence.size())), FSEND); - for (size_t nMember : aMemberSequence) + for (const auto & nMember : aMemberSequence) { - pPivotStrm->singleElement(XML_item, - XML_x, OString::number(static_cast(nMember)), - FSEND); + auto pItemAttList = sax_fastparser::FastSerializerHelper::createAttrList(); + if (nMember.second) + pItemAttList->add(XML_h, ToPsz10(true)); + pItemAttList->add(XML_x, OString::number(static_cast(nMember.first))); + sax_fastparser::XFastAttributeListRef xItemAttributeList(pItemAttList); + pPivotStrm->singleElement(XML_item, xItemAttributeList); } for (const OString& sSubtotal : aSubtotalSequence)