summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-01-16 09:40:11 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2018-01-16 09:36:49 +0100
commit46b3202bf883618f1585850191c19776861013ed (patch)
treeb2b68cc37a4c9c6bedc85df5e243c6cb239f30c6
parent5787f5b393ac8d239c043391e24ab91179d0ef1d (diff)
tdf#115013: write merge field column into docx merge fields
Change-Id: If1e0a8968407c72e42cb7ca487541d0b8227aabc Reviewed-on: https://gerrit.libreoffice.org/47895 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--sw/qa/extras/uiwriter/data/datasource.odsbin0 -> 8038 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx47
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx3
3 files changed, 49 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/data/datasource.ods b/sw/qa/extras/uiwriter/data/datasource.ods
new file mode 100644
index 000000000000..076659679575
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/datasource.ods
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 1bfb252c4899..9f4597486f3e 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -61,6 +61,7 @@
#include <i18nutil/transliteration.hxx>
#include <i18nutil/searchopt.hxx>
#include <reffld.hxx>
+#include <dbfld.hxx>
#include <txatbase.hxx>
#include <ftnidx.hxx>
#include <txtftn.hxx>
@@ -294,6 +295,7 @@ public:
void testTdf108048();
void testTdf114306();
void testTdf113481();
+ void testTdf115013();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -468,6 +470,7 @@ public:
CPPUNIT_TEST(testTdf108048);
CPPUNIT_TEST(testTdf114306);
CPPUNIT_TEST(testTdf113481);
+ CPPUNIT_TEST(testTdf115013);
CPPUNIT_TEST_SUITE_END();
private:
@@ -5744,6 +5747,50 @@ void SwUiWriterTest::testTdf113481()
CPPUNIT_ASSERT_EQUAL(u'\x1820', xPara3->getString()[0]);
}
+void SwUiWriterTest::testTdf115013()
+{
+ //create new writer document
+ SwDoc* pDoc = createDoc();
+
+ {
+ // Load and register data source
+ const OUString aDataSourceURI(m_directories.getURLFromSrc(DATA_DIRECTORY) + "datasource.ods");
+ OUString sDataSource = SwDBManager::LoadAndRegisterDataSource(aDataSourceURI, nullptr);
+ CPPUNIT_ASSERT(!sDataSource.isEmpty());
+
+ // Insert a new field type for the mailmerge field
+ SwDBData aDBData;
+ aDBData.sDataSource = sDataSource;
+ aDBData.sCommand = "Sheet1";
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ CPPUNIT_ASSERT(pWrtShell);
+ SwDBFieldType* pFieldType = static_cast<SwDBFieldType*>(pWrtShell->InsertFieldType(
+ SwDBFieldType(pDoc, "Name", aDBData)));
+ CPPUNIT_ASSERT(pFieldType);
+
+ // Insert the field into document
+ SwDBField aField(pFieldType);
+ pWrtShell->Insert(aField);
+ }
+ // Save it as DOCX & load it again
+ reload("Office Open XML Text", "mm-field.docx");
+
+ CPPUNIT_ASSERT(mxComponent.get());
+ pDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get())->GetDocShell()->GetDoc();
+ CPPUNIT_ASSERT(pDoc);
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ CPPUNIT_ASSERT(pWrtShell);
+ SwPaM* pCursor = pDoc->GetEditShell()->GetCursor();
+ CPPUNIT_ASSERT(pCursor);
+
+ // Get the field at the beginning of the document
+ SwDBField* pField = dynamic_cast<SwDBField*>(SwCursorShell::GetFieldAtCursor(pCursor, true));
+ CPPUNIT_ASSERT(pField);
+ OUString sColumn = static_cast<SwDBFieldType*>(pField->GetTyp())->GetColumnName();
+ // The column name must come correct after round trip
+ CPPUNIT_ASSERT_EQUAL(OUString("Name"), sColumn);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 1d04d2b3e8b5..233126c05439 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -122,6 +122,7 @@
#include <chpfld.hxx>
#include <fmthdft.hxx>
#include <authfld.hxx>
+#include <dbfld.hxx>
#include "sprmids.hxx"
@@ -2756,7 +2757,7 @@ void AttributeOutputBase::TextField( const SwFormatField& rField )
break;
case SwFieldIds::Database:
{
- OUString sStr = FieldString(ww::eMERGEFIELD) + pField->GetPar1() + " ";
+ OUString sStr = FieldString(ww::eMERGEFIELD) + static_cast<SwDBFieldType *>(pField->GetTyp())->GetColumnName() + " ";
GetExport().OutputField(pField, ww::eMERGEFIELD, sStr);
}
break;