summaryrefslogtreecommitdiff
path: root/sw
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
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')
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf67207.docxbin0 -> 5186 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport11.cxx32
-rw-r--r--sw/source/filter/ww8/docxexport.cxx23
3 files changed, 55 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf67207.docx b/sw/qa/extras/ooxmlexport/data/tdf67207.docx
new file mode 100644
index 000000000000..b0604c266394
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf67207.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index 1e2bd17db9a7..7d9b392f635b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -988,6 +988,38 @@ DECLARE_OOXMLIMPORT_TEST(testTdf123054, "tdf123054.docx")
getProperty<OUString>(getParagraph(20), "ParaStyleName"));
}
+DECLARE_OOXMLEXPORT_TEST(testTdf67207_MERGEFIELD_DATABASE, "tdf67207.docx")
+{
+ // database fields use the database "database" and its table "Sheet1"
+ uno::Reference<beans::XPropertySet> xTextField = getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(2), 2), "TextField");
+ CPPUNIT_ASSERT(xTextField.is());
+ uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY_THROW);
+ uno::Reference<text::XDependentTextField> xDependent(xTextField, uno::UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextField.Database"));
+ OUString sValue;
+ xTextField->getPropertyValue("Content") >>= sValue;
+ CPPUNIT_ASSERT_EQUAL(OUString::fromUtf8("<c1>"), sValue);
+
+ uno::Reference<beans::XPropertySet> xFiledMaster = xDependent->getTextFieldMaster();
+ uno::Reference<lang::XServiceInfo> xFiledMasterServiceInfo(xFiledMaster, uno::UNO_QUERY_THROW);
+
+ CPPUNIT_ASSERT(xFiledMasterServiceInfo->supportsService("com.sun.star.text.fieldmaster.Database"));
+
+ // Defined properties: DataBaseName, Name, DataTableName, DataColumnName, DependentTextFields, DataCommandType, InstanceName, DataBaseURL
+ CPPUNIT_ASSERT(xFiledMaster->getPropertyValue("DataBaseName") >>= sValue);
+ CPPUNIT_ASSERT_EQUAL(OUString("database"), sValue);
+ sal_Int32 nCommandType;
+ CPPUNIT_ASSERT(xFiledMaster->getPropertyValue("DataCommandType") >>= nCommandType);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nCommandType); // css::sdb::CommandType::TABLE
+ CPPUNIT_ASSERT(xFiledMaster->getPropertyValue("DataTableName") >>= sValue);
+ CPPUNIT_ASSERT_EQUAL(OUString("Sheet1"), sValue);
+ CPPUNIT_ASSERT(xFiledMaster->getPropertyValue("DataColumnName") >>= sValue);
+ CPPUNIT_ASSERT_EQUAL(OUString("c1"), sValue);
+ CPPUNIT_ASSERT(xFiledMaster->getPropertyValue("InstanceName") >>= sValue);
+ CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.text.fieldmaster.DataBase.database.Sheet1.c1"), sValue);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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);