summaryrefslogtreecommitdiff
path: root/sw/source/filter
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2019-04-24 12:30:56 +0200
committerLászló Németh <nemeth@numbertext.org>2019-04-26 08:28:11 +0200
commit071c3309260aeae22f464d26bfa56a747f6a02cb (patch)
treea09f43b6ccbca9d61a48d6075ca23e9ac43bfd49 /sw/source/filter
parente1a75c1c3069efa303c480d0e50928c0761f468f (diff)
tdf#67207 DOCX mail merge: fix export/import of database fields
to support the registered databases (containing ODS, XLSX sheet or ODT text table data sources). Now database fields don't lose their database connection, and File->Print can merge mails after DOCX export/import, if the LO instance has got a registered database with the same name and table, as in saved in w:settings/w:mailMerge/w:query element of the DOCX document in the form of SELECT * FROM [databaseName].dbo.[tableName]$ query. Notes: – This fix supports only single table usage. – The exported DOCX document is editable in MSO, too, without losing the database connection in LO later. Change-Id: I97826b7ee7defd0243dbaffa0325c5b11dd2c0d1 Reviewed-on: https://gerrit.libreoffice.org/71228 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/source/filter')
-rw-r--r--sw/source/filter/ww8/docxexport.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 501f632ff3f2..3b9e677e7219 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -33,6 +33,7 @@
#include <com/sun/star/xml/sax/XSAXSerializable.hpp>
#include <com/sun/star/xml/sax/Writer.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
+#include <com/sun/star/sdb/CommandType.hpp>
#include <oox/token/namespaces.hxx>
#include <oox/token/tokens.hxx>
@@ -63,6 +64,7 @@
#include <section.hxx>
#include <ftninfo.hxx>
#include <pagedesc.hxx>
+#include <swdbdata.hxx>
#include <editeng/unoprnms.hxx>
#include <editeng/editobj.hxx>
@@ -979,6 +981,27 @@ void DocxExport::WriteSettings()
pFS->endElementNS( XML_w, XML_compat );
}
+ // export current mail merge database and table names
+ SwDBData aData = m_pDoc->GetDBData();
+ if ( !aData.sDataSource.isEmpty() && aData.nCommandType == css::sdb::CommandType::TABLE && !aData.sCommand.isEmpty() )
+ {
+ OUStringBuffer aDataSource;
+ aDataSource.append("SELECT * FROM ");
+ aDataSource.append(aData.sDataSource); // current database
+ aDataSource.append(".dbo."); // default database owner
+ aDataSource.append(aData.sCommand); // sheet name
+ aDataSource.append("$"); // sheet identifier
+ const OUString sDataSource = aDataSource.makeStringAndClear();
+ pFS->startElementNS( XML_w, XML_mailMerge );
+ pFS->singleElementNS(XML_w, XML_mainDocumentType,
+ FSNS( XML_w, XML_val ), "formLetters" );
+ pFS->singleElementNS(XML_w, XML_dataType,
+ FSNS( XML_w, XML_val ), "textFile" );
+ pFS->singleElementNS( XML_w, XML_query,
+ FSNS( XML_w, XML_val ), OUStringToOString( sDataSource, RTL_TEXTENCODING_UTF8 ).getStr() );
+ pFS->endElementNS( XML_w, XML_mailMerge );
+ }
+
// Automatic hyphenation: it's a global setting in Word, it's a paragraph setting in Writer.
// Use the setting from the default style.
SwTextFormatColl* pColl = m_pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, /*bRegardLanguage=*/false);