summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2017-08-29 23:12:23 +0200
committerTamás Zolnai <tamas.zolnai@collabora.com>2017-08-30 00:06:29 +0200
commitb90bdb1c0d27fd87c85a2d1d6ea66070b97b7977 (patch)
treec098bb49dfe8fb2e9773a83fe178002c273b0edd
parenta9cd75c1501d5095887c657426820962c68e0ede (diff)
tdf#108352: Structure of pivot table coming from XLS is altered in LO
Change-Id: I001daeaa12cd41cc36033a26457f960d8b8a5c0e Reviewed-on: https://gerrit.libreoffice.org/41713 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r--sc/inc/dpoutputgeometry.hxx2
-rwxr-xr-xsc/qa/unit/data/xls/pivot_row_header.xlsbin0 -> 27136 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx73
-rw-r--r--sc/source/core/data/dpoutputgeometry.cxx10
-rw-r--r--sc/source/filter/excel/xipivot.cxx7
5 files changed, 90 insertions, 2 deletions
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
--- /dev/null
+++ b/sc/qa/unit/data/xls/pivot_row_header.xls
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 2ba55186cd30..c07f28af1f26 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -45,6 +45,7 @@
#include <dpsave.hxx>
#include <dputil.hxx>
#include "validat.hxx"
+#include <attrib.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdpage.hxx>
@@ -169,6 +170,7 @@ public:
void testPivotTableXLSX();
void testPivotTableTwoDataFieldsXLSX();
void testPivotTableMedianODS();
+ void testPivotTableRowHeaderXLS();
void testSwappedOutImageExport();
void testLinkedGraphicRT();
@@ -272,6 +274,7 @@ public:
CPPUNIT_TEST(testPivotTableXLSX);
CPPUNIT_TEST(testPivotTableTwoDataFieldsXLSX);
CPPUNIT_TEST(testPivotTableMedianODS);
+ CPPUNIT_TEST(testPivotTableRowHeaderXLS);
#if !defined(_WIN32)
CPPUNIT_TEST(testSupBookVirtualPathXLS);
#endif
@@ -4185,6 +4188,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 18941fc352ce..89ec062c7089 100644
--- a/sc/source/filter/excel/xipivot.cxx
+++ b/sc/source/filter/excel/xipivot.cxx
@@ -1446,6 +1446,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;