sw/qa/extras/ooxmlexport/ooxmlexport17.cxx | 34 +++++++++++++++++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 18 ++++++++++++++ 2 files changed, 52 insertions(+)
New commits: commit c04e1a32a1610c735ef2de6e8fde107abb1b66ae Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri May 27 08:06:18 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue May 31 14:40:08 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> (cherry picked from commit 10b1a9eb8588e15ea5e98001cc4d5ab2d56604f3) Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport17.cxx Change-Id: I4695ac30be26968b2c2ea14b044c1e2a10638ea8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135149 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx index c428d0225611..c0a0d401da35 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx @@ -274,6 +274,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"); +} + DECLARE_OOXMLEXPORT_TEST(testTdf137466, "tdf137466.docx") { xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 7e30ec38e1ac..f253e77658d7 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2380,6 +2380,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;