sw/qa/extras/ooxmlexport/ooxmlexport17.cxx | 34 +++++++++++++++++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 18 ++++++++++++++ 2 files changed, 52 insertions(+)
New commits: commit 10b1a9eb8588e15ea5e98001cc4d5ab2d56604f3 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri May 27 08:06:18 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri May 27 08:44:10 2022 +0200 sw content controls, date: add DOCX export Map the Date, DateFormat and DateLanguage UNO properties to: <w:date> <w:dateFormat w:val="..."/> <w:lid w:val="..."/> </w:date> Change-Id: I4695ac30be26968b2c2ea14b044c1e2a10638ea8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135033 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx index fd6c560395b5..2ba7a7cfdd97 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx @@ -371,6 +371,40 @@ CPPUNIT_TEST_FIXTURE(Test, testPictureContentControlExport) assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:picture", 1); } +CPPUNIT_TEST_FIXTURE(Test, testDateContentControlExport) +{ + // Given a document with a date content control around a text portion: + mxComponent = loadFromDesktop("private:factory/swriter"); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Date", uno::Any(true)); + xContentControlProps->setPropertyValue("DateFormat", uno::Any(OUString("M/d/yyyy"))); + xContentControlProps->setPropertyValue("DateLanguage", uno::Any(OUString("en-US"))); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When exporting to DOCX: + save("Office Open XML Text", maTempFile); + mbExported = true; + + // Then make sure the expected markup is used: + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + // Without the fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '//w:sdt/w:sdtPr/w:date/w:dateFormat' number of nodes is incorrect + // i.e. the <w:date> was lost on export. + assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:date/w:dateFormat", "val", "M/d/yyyy"); + assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:date/w:lid", "val", "en-US"); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf148494) { loadAndSave("tdf148494.docx"); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 6d179315d456..3d9835ef410a 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2372,6 +2372,24 @@ void DocxAttributeOutput::WriteContentControlStart() m_pSerializer->endElementNS(XML_w, XML_dropDownList); } + if (m_pContentControl->GetDate()) + { + m_pSerializer->startElementNS(XML_w, XML_date); + OUString aDateFormat = m_pContentControl->GetDateFormat(); + if (!aDateFormat.isEmpty()) + { + m_pSerializer->singleElementNS(XML_w, XML_dateFormat, FSNS(XML_w, XML_val), + aDateFormat); + } + OUString aDateLanguage = m_pContentControl->GetDateLanguage(); + if (!aDateLanguage.isEmpty()) + { + m_pSerializer->singleElementNS(XML_w, XML_lid, FSNS(XML_w, XML_val), + aDateLanguage); + } + m_pSerializer->endElementNS(XML_w, XML_date); + } + m_pSerializer->endElementNS(XML_w, XML_sdtPr); m_pSerializer->startElementNS(XML_w, XML_sdtContent); m_pContentControl = nullptr;