sc/inc/dpoutputgeometry.hxx | 2 sc/qa/unit/data/xls/pivot_row_header.xls |binary sc/qa/unit/subsequent_export-test.cxx | 73 +++++++++++++++++++++++++++++++ sc/source/core/data/dpoutputgeometry.cxx | 10 +++- sc/source/filter/excel/xipivot.cxx | 7 ++ 5 files changed, 90 insertions(+), 2 deletions(-)
New commits: commit 6dbc5ea586465514d6c1942a90bf15eb928ebdd5 Author: Tamás Zolnai <tamas.zol...@collabora.com> Date: Wed Aug 30 00:16:24 2017 +0200 tdf#108352: Structure of pivot table coming from XLS is altered in LO Reviewed-on: https://gerrit.libreoffice.org/41713 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> (cherry picked from commit b90bdb1c0d27fd87c85a2d1d6ea66070b97b7977) Change-Id: I001daeaa12cd41cc36033a26457f960d8b8a5c0e Reviewed-on: https://gerrit.libreoffice.org/41717 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> diff --git a/sc/inc/dpoutputgeometry.hxx b/sc/inc/dpoutputgeometry.hxx index d5202ae23b85..f4896fc1c3ec 100644 --- a/sc/inc/dpoutputgeometry.hxx +++ b/sc/inc/dpoutputgeometry.hxx @@ -42,6 +42,7 @@ public: void setPageFieldCount(sal_uInt32 nCount); void setDataFieldCount(sal_uInt32 nCount); void setDataLayoutType(FieldType eType); + void setHeaderLayout(bool bHeaderLayout); void getColumnFieldPositions(::std::vector<ScAddress>& rAddrs) const; void getRowFieldPositions(::std::vector<ScAddress>& rAddrs) const; @@ -62,6 +63,7 @@ private: sal_uInt32 mnDataFields; FieldType meDataLayoutType; bool mbShowFilter; + bool mbHeaderLayout; }; #endif diff --git a/sc/qa/unit/data/xls/pivot_row_header.xls b/sc/qa/unit/data/xls/pivot_row_header.xls new file mode 100755 index 000000000000..36cbb7e8616f Binary files /dev/null and b/sc/qa/unit/data/xls/pivot_row_header.xls differ diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index 13598b5b0423..b8559ec3f6a4 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -41,6 +41,7 @@ #include <dpobject.hxx> #include <dpsave.hxx> #include <dputil.hxx> +#include <attrib.hxx> #include <svx/svdoole2.hxx> #include <svx/svdpage.hxx> @@ -157,6 +158,7 @@ public: void testPivotTableXLSX(); void testPivotTableTwoDataFieldsXLSX(); void testPivotTableMedian(); + void testPivotTableRowHeaderXLS(); void testSwappedOutImageExport(); void testLinkedGraphicRT(); @@ -254,6 +256,7 @@ public: CPPUNIT_TEST(testPivotTableXLSX); CPPUNIT_TEST(testPivotTableTwoDataFieldsXLSX); CPPUNIT_TEST(testPivotTableMedian); + CPPUNIT_TEST(testPivotTableRowHeaderXLS); #if !defined(_WIN32) CPPUNIT_TEST(testSupBookVirtualPath); #endif @@ -4082,6 +4085,76 @@ void ScExportTest::testHyperlinkTargetFrameODS() CPPUNIT_ASSERT_EQUAL(OUString("_blank"), aTargetFrameExport); } +void ScExportTest::testPivotTableRowHeaderXLS() +{ + ScDocShellRef xDocSh = loadDoc("pivot_row_header.", FORMAT_XLS); + CPPUNIT_ASSERT_MESSAGE("Failed to load file", xDocSh.Is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // There should be exactly 2 pivot tables + ScDPCollection* pDPs = rDoc.GetDPCollection(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pDPs->GetCount()); + + // First table has extra row header + { + const ScDPObject* pDPObj = &(*pDPs)[0]; + CPPUNIT_ASSERT_MESSAGE("Failed to get an pivot table object.", pDPObj); + CPPUNIT_ASSERT(pDPObj->GetHeaderLayout()); + // Check whether the row header has the right popupbutton flag + const ScPatternAttr* pPattern = rDoc.GetPattern(3, 3, 0); + const SfxPoolItem& rPoolItem = pPattern->GetItem(ATTR_MERGE_FLAG); + const ScMergeFlagAttr& rMergeFlag = static_cast<const ScMergeFlagAttr&>(rPoolItem); + CPPUNIT_ASSERT(rMergeFlag.GetValue() & ScMF::ButtonPopup); + } + + // Second table has no extra row header + { + const ScDPObject* pDPObj = &(*pDPs)[1]; + CPPUNIT_ASSERT_MESSAGE("Failed to get an pivot table object.", pDPObj); + CPPUNIT_ASSERT(!pDPObj->GetHeaderLayout()); + // Check whether the row header has the right popupbutton flag + const ScPatternAttr* pPattern = rDoc.GetPattern(0, 2, 0); + const SfxPoolItem& rPoolItem = pPattern->GetItem(ATTR_MERGE_FLAG); + const ScMergeFlagAttr& rMergeFlag = static_cast<const ScMergeFlagAttr&>(rPoolItem); + CPPUNIT_ASSERT(rMergeFlag.GetValue() & ScMF::ButtonPopup); + } + + // Check also after a reload + xDocSh = saveAndReload( &(*xDocSh), FORMAT_XLS); + CPPUNIT_ASSERT_MESSAGE("Failed to load file", xDocSh.Is()); + ScDocument& rLoadedDoc = xDocSh->GetDocument(); + + // There should be exactly 2 pivot tables + pDPs = rLoadedDoc.GetDPCollection(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pDPs->GetCount()); + + // First table has extra row header + { + const ScDPObject* pDPObj = &(*pDPs)[0]; + CPPUNIT_ASSERT_MESSAGE("Failed to get an pivot table object.", pDPObj); + CPPUNIT_ASSERT(pDPObj->GetHeaderLayout()); + // Check whether the row header has the right popupbutton flag + const ScPatternAttr* pPattern = rLoadedDoc.GetPattern(3, 3, 0); + const SfxPoolItem& rPoolItem = pPattern->GetItem(ATTR_MERGE_FLAG); + const ScMergeFlagAttr& rMergeFlag = static_cast<const ScMergeFlagAttr&>(rPoolItem); + CPPUNIT_ASSERT(rMergeFlag.GetValue() & ScMF::ButtonPopup); + } + + // Second table has no extra row header + { + const ScDPObject* pDPObj = &(*pDPs)[1]; + CPPUNIT_ASSERT_MESSAGE("Failed to get an pivot table object.", pDPObj); + CPPUNIT_ASSERT(!pDPObj->GetHeaderLayout()); + // Check whether the row header has the right popupbutton flag + const ScPatternAttr* pPattern = rLoadedDoc.GetPattern(0, 2, 0); + const SfxPoolItem& rPoolItem = pPattern->GetItem(ATTR_MERGE_FLAG); + const ScMergeFlagAttr& rMergeFlag = static_cast<const ScMergeFlagAttr&>(rPoolItem); + CPPUNIT_ASSERT(rMergeFlag.GetValue() & ScMF::ButtonPopup); + } + + xDocSh->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/core/data/dpoutputgeometry.cxx b/sc/source/core/data/dpoutputgeometry.cxx index 53a600070470..23138d2fe7af 100644 --- a/sc/source/core/data/dpoutputgeometry.cxx +++ b/sc/source/core/data/dpoutputgeometry.cxx @@ -31,7 +31,8 @@ ScDPOutputGeometry::ScDPOutputGeometry(const ScRange& rOutRange, bool bShowFilte mnPageFields(0), mnDataFields(0), meDataLayoutType(None), - mbShowFilter(bShowFilter) + mbShowFilter(bShowFilter), + mbHeaderLayout (false) { } @@ -64,6 +65,11 @@ void ScDPOutputGeometry::setDataLayoutType(FieldType eType) meDataLayoutType = eType; } +void ScDPOutputGeometry::setHeaderLayout(bool bHeaderLayout) +{ + mbHeaderLayout = bHeaderLayout; +} + void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const { sal_uInt32 nColumnFields, nRowFields; @@ -156,7 +162,7 @@ SCROW ScDPOutputGeometry::getRowFieldHeaderRow() const if (nColumnFields) nCurRow += static_cast<SCROW>(nColumnFields); - else if (nRowFields) + else if (nRowFields && mbHeaderLayout) ++nCurRow; return nCurRow; diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx index d8844fe65b15..e735414f03db 100644 --- a/sc/source/filter/excel/xipivot.cxx +++ b/sc/source/filter/excel/xipivot.cxx @@ -1447,6 +1447,13 @@ void XclImpPivotTable::ApplyMergeFlags(const ScRange& rOutRange, const ScDPSaveD aGeometry.setDataFieldCount(maPTInfo.mnDataFields); aGeometry.setRowFieldCount(maPTInfo.mnRowFields); + // Make sure we set headerlayout when input file has additional raw header + if(maPTInfo.mnColFields == 0) + { + mpDPObj->SetHeaderLayout( maPTInfo.mnFirstHeadRow - 2 == static_cast<sal_uInt16>(aGeometry.getRowFieldHeaderRow()) ); + } + aGeometry.setHeaderLayout(mpDPObj->GetHeaderLayout()); + ScDocument& rDoc = GetDoc(); vector<const ScDPSaveDimension*> aFieldDims;
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits