Kaydet (Commit) 577b95f4 authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#124651: always write "name" attribute to dataField element

Despite being optional as per ECMA-376-1:2016, Excel 2016 seems to
require the presence of "name" attribute in dataField element of
pivot table definition, so make sure to write at least empty string
there.

Change-Id: Iaab5674f86b7dd0b267776678e11af47086635d7
Reviewed-on: https://gerrit.libreoffice.org/70522Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
Tested-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst f315fee5
......@@ -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();
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment