diff options
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 55 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.hxx | 3 |
2 files changed, 58 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 526d100768c8..992a97d69103 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/xml/sax/Writer.hpp> #include <com/sun/star/awt/XControlModel.hpp> #include <com/sun/star/sdb/CommandType.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> #include <oox/token/namespaces.hxx> #include <oox/token/tokens.hxx> @@ -887,6 +888,58 @@ void DocxExport::WriteProperties( ) m_pFilter->exportDocumentProperties( xDocProps, bSecurityOptOpenReadOnly ); } +void DocxExport::WriteDocVars(const sax_fastparser::FSHelperPtr& pFS) +{ + SwDocShell* pDocShell = m_pDoc->GetDocShell(); + if (!pDocShell) + { + return; + } + + uno::Reference<text::XTextFieldsSupplier> xModel(pDocShell->GetModel(), uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xTextFieldMasters = xModel->getTextFieldMasters(); + uno::Sequence<rtl::OUString> aMasterNames = xTextFieldMasters->getElementNames(); + if (!aMasterNames.hasElements()) + { + return; + } + + // Only write docVars if there will be at least a single docVar. + bool bStarted = false; + const OUStringLiteral aPrefix("com.sun.star.text.fieldmaster.User."); + for (const auto& rMasterName : std::as_const(aMasterNames)) + { + if (!rMasterName.startsWith(aPrefix)) + { + // Not a user field. + continue; + } + + uno::Reference<beans::XPropertySet> xField; + xTextFieldMasters->getByName(rMasterName) >>= xField; + if (!xField.is()) + { + continue; + } + + OUString aKey = rMasterName.copy(aPrefix.getLength()); + OUString aValue; + xField->getPropertyValue("Content") >>= aValue; + if (!bStarted) + { + bStarted = true; + pFS->startElementNS(XML_w, XML_docVars); + } + pFS->singleElementNS(XML_w, XML_docVar, FSNS(XML_w, XML_name), aKey.toUtf8(), + FSNS(XML_w, XML_val), aValue.toUtf8()); + } + + if (bStarted) + { + pFS->endElementNS(XML_w, XML_docVars); + } +} + void DocxExport::WriteSettings() { SwViewShell *pViewShell(m_pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()); @@ -1151,6 +1204,8 @@ void DocxExport::WriteSettings() } } + WriteDocVars(pFS); + // Protect form // Section-specific write protection if (! hasProtectionProperties) diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx index 00b908dc7efa..f659cd1244f4 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -245,6 +245,9 @@ private: /// Write word/settings.xml void WriteSettings(); + /// Writes the <w:docVars> part of settings.xml + void WriteDocVars(const sax_fastparser::FSHelperPtr& pFS); + /// Write word/theme/theme1.xml void WriteTheme(); |