I have a problem implementing MailMerge with ODT template document.
How could I define a TableStart and TableEnd tags as Field ?
With doc or docx template I can define a Field as “TableStart:Invoice” without problem, but with OpenOffice the character “:” is not available as part of a Field name.
This is my c# code:
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_MailMergeAndReporting(); ;
// Create the Dataset and read the XML.
DataSet invoiceDs = new DataSet();
/*
* <?xml version="1.0" encoding="utf-8"?>
<Invoices xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="InvoicesSchema.xsd">
<Invoice>
<Number>223</Number>
<customer>BandB Hotel</customer>
<Amount>1465,00</Amount>
</Invoice>
</Invoices>
*/
invoiceDs.ReadXml(dataDir + "InvoiceData.xml");
// Open the template document.
Document doc = new Document(dataDir + "Invoice Template.odt");
// Execute the nested mail merge with regions
doc.MailMerge.ExecuteWithRegions(invoiceDs);
string docFullPath = dataDir + "Invoice Out.odt";
// Save the output to file
doc.Save(docFullPath, SaveFormat.Odt);
Debug.Assert(doc.MailMerge.GetFieldNames().Length == 0, "There was a problem with mail merge");
Console.WriteLine("\nMail merge performed with nested data successfully.\nFile saved as {0}", docFullPath);
thanks
Alberto
Hi Alberto,
Thanks for your inquiry. To use mail merge with region, your template should contain mergefields with names TableStart:RegionName and TableEnd:RegionName. You can programmatically insert these fields using DocumentBuilder.InsertField method at the desired location. Please check the attached document and following code example. Hope this helps you.
DataTable data = new DataTable("Test");
data.Columns.Add("test");
for (int i = 0; i < 10; i++)
data.Rows.Add(new object[] { string.Format("test_{0}", i) });
Document doc = new Document(MyDir + @"input.odt");
doc.MailMerge.ExecuteWithRegions(data);
doc.Save(MyDir + "Out v16.8.0.odt");
Hi,
thank you for you suggestion, but I need to define statically (not programmatically ) the region on .odt file using OpenOffice application.
My problem is that OpenOffice cannot leave me specify as field name the string: “TableStart:RegionName”.
In your sample (input.odt) the string «TableStart:Test» is a simple string, not a “FIELD” definition. I’m using Apace OpenOffice 4.1.2.
If you see my attachment, I would create “TableStart:Test” in the same manner as “PROVA” Field. Can I do that ?
Regards.
Hi Alberto,
Thanks for your inquiry.
In this case, we suggest you please add the database file from Insert->Fields->Other->Database tab and database should contains the fields TableStart:RegionName and TableEnd:RegionName. Please check the attached image for detail. We have attached a sample input document for your kind reference.