summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-07-08 10:15:29 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-07-08 11:06:31 +0200
commitd67085cd86dc1e74941c8337d1eba39981117977 (patch)
tree9e24a58299c66f93ef05743e6b44dc75bda3fdd9
parent8726cf692299ea262a7455adcf6ec25451c7869d (diff)
XSLX export, button form control: fix handling of no macros
Turns out that in case there is no macro, then the attribute should be omitted, leaving it empty is not OK. Excel warns about this. Change-Id: I2dbc4d837bd585674e013eb3ce6b898f12498c4d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118600 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sc/qa/unit/subsequent_export-test2.cxx6
-rw-r--r--sc/source/filter/excel/xeescher.cxx5
2 files changed, 10 insertions, 1 deletions
diff --git a/sc/qa/unit/subsequent_export-test2.cxx b/sc/qa/unit/subsequent_export-test2.cxx
index 0a44090734ab..74e795709b0e 100644
--- a/sc/qa/unit/subsequent_export-test2.cxx
+++ b/sc/qa/unit/subsequent_export-test2.cxx
@@ -2367,6 +2367,12 @@ void ScExportTest2::testButtonFormControlXlsxExport()
assertXPathContent(pDoc, "//x:anchor/x:from/xdr:row", "3");
assertXPathContent(pDoc, "//x:anchor/x:to/xdr:col", "3");
assertXPathContent(pDoc, "//x:anchor/x:to/xdr:row", "7");
+
+ // Also make sure that an empty macro attribute is not written.
+ // Without the fix in place, this test would have failed with:
+ // - XPath '//x:controlPr' unexpected 'macro' attribute
+ // i.e. macro in an xlsx file was not omitted, which is considered invalid by Excel.
+ assertXPathNoAttribute(pDoc, "//x:controlPr", "macro");
}
void ScExportTest2::testInvalidNamedRange()
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index eafc30de8b0a..2f92384c25b4 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -1481,9 +1481,12 @@ void XclExpTbxControlObj::SaveSheetXml(XclExpXmlStream& rStrm, const OUString& a
rWorksheet->startElement(XML_control, XML_shapeId, OString::number(mnShapeId).getStr(),
FSNS(XML_r, XML_id), aIdFormControlPr, XML_name, msCtrlName);
+ OString aMacroName = GetMacroName().toUtf8();
+ // Omit the macro attribute if it would be empty.
+ const char* pMacroName = aMacroName.isEmpty() ? nullptr : aMacroName.getStr();
rWorksheet->startElement(XML_controlPr, XML_defaultSize, "0", XML_print,
mbPrint ? "true" : "false", XML_autoFill, "0", XML_autoPict,
- "0", XML_macro, GetMacroName());
+ "0", XML_macro, pMacroName);
rWorksheet->startElement(XML_anchor, XML_moveWithCells, "true", XML_sizeWithCells,
"false");