diff options
-rw-r--r-- | sc/qa/unit/data/ods/tdf124651_simplePivotTable.ods | bin | 0 -> 10427 bytes | |||
-rw-r--r-- | sc/qa/unit/pivottable_filters_test.cxx | 15 | ||||
-rw-r--r-- | sc/source/filter/excel/xepivotxml.cxx | 7 |
3 files changed, 20 insertions, 2 deletions
diff --git a/sc/qa/unit/data/ods/tdf124651_simplePivotTable.ods b/sc/qa/unit/data/ods/tdf124651_simplePivotTable.ods Binary files differnew file mode 100644 index 000000000000..05fd5fec838f --- /dev/null +++ b/sc/qa/unit/data/ods/tdf124651_simplePivotTable.ods diff --git a/sc/qa/unit/pivottable_filters_test.cxx b/sc/qa/unit/pivottable_filters_test.cxx index 739af618ec7d..d5b1afd64701 100644 --- a/sc/qa/unit/pivottable_filters_test.cxx +++ b/sc/qa/unit/pivottable_filters_test.cxx @@ -85,6 +85,7 @@ public: void testTdf112106(); void testTdf123923(); void testTdf123939(); + void testTdf124651(); CPPUNIT_TEST_SUITE(ScPivotTableFiltersTest); @@ -127,6 +128,7 @@ public: CPPUNIT_TEST(testTdf112106); CPPUNIT_TEST(testTdf123923); CPPUNIT_TEST(testTdf123939); + CPPUNIT_TEST(testTdf124651); CPPUNIT_TEST_SUITE_END(); @@ -2430,6 +2432,19 @@ void ScPivotTableFiltersTest::testTdf123939() "containsMixedTypes", "1"); } +void ScPivotTableFiltersTest::testTdf124651() +{ + ScDocShellRef xDocSh = loadDoc("tdf124651_simplePivotTable.", FORMAT_ODS); + CPPUNIT_ASSERT(xDocSh.is()); + + xmlDocPtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, + "xl/pivotTables/pivotTable1.xml", FORMAT_XLSX); + CPPUNIT_ASSERT(pDoc); + // We have to export name attribute, even though it's optional according to ECMA-376 standard, + // because Excel (at least 2016) seems to require it. + assertXPath(pDoc, "/x:pivotTableDefinition/x:dataFields/x:dataField", "name", ""); +} + 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 1a47e2cfeb5b..69c98d13c55b 100644 --- a/sc/source/filter/excel/xepivotxml.cxx +++ b/sc/source/filter/excel/xepivotxml.cxx @@ -947,9 +947,12 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP assert(aCachedDims[nDimIdx]); // the loop above should have screened for NULL's. const ScDPSaveDimension& rDim = *rDataField.mpDim; const boost::optional<OUString> & pName = rDim.GetLayoutName(); + // tdf#124651: despite being optional in CT_DataField according to ECMA-376 Part 1, + // Excel (at least 2016) seems to insist on the presence of "name" attribute in + // dataField element, even if empty + const OString sName = pName ? pName->toUtf8() : ""; pPivotStrm->write("<")->writeId(XML_dataField); - if (pName) - rStrm.WriteAttributes(XML_name, pName->toUtf8(), FSEND); + rStrm.WriteAttributes(XML_name, sName, FSEND); rStrm.WriteAttributes(XML_fld, OString::number(nDimIdx).getStr(), FSEND); |