Free Support Forum - aspose.com

ODT : Aspose.Word ExecuteWithRegions(ds)

Hi,

I'm trying to use Aspose.Word 9.0.0 to generate an OpenOffice Writter document with region.

Source :
License licence = new License();
licence.SetLicense(Utils.GetAsposeLicenceFullPath());
Document document = new Document(PathTmpModele);
document.MailMerge.ExecuteWithRegions(ds);
document.UpdateFields();
document.Save(FichierSortie,SaveFormat.Odt);

Dataset ds and Odt document are attached

Could you please give me an exemple of Odt generation whith ExecuteWithRegion ? I don't see how to link data with sections in my document to repeat them for each record.

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. To use mail merge feature, you need to insert merge fields in your template:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/prepare-a-document.html

Here you can learn how to format regions:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/mail-merge-with-regions-explained.html

Hope this helps. Please let me know in case of any issues, I will be glad to help you.

Best regards.

Hi Alexey,

Thanks for reply.

I'm already using Microsoft Word template. Could you please give me some information about OpenOffice Writer template ? How must be declared region and mergefield in an odt document to work with Aspose Word ? (I load an odt template in my Aspose.Word document)

Max

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. To use mail merge with region, your template should contain mergefields with names TableStart:RegionName or TableStart_RegionName and TableEnd:RegionName or TableEnd_RegionName. Such fields marks start and end of document’s portion, which should be repeated for each record in your datasource. I attached sample ODT template for your reference. Here is code I use to fill it with data:

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(@"Test001\in.odt");

doc.MailMerge.ExecuteWithRegions(data);

doc.Save(@"Test001\out.odt");

Also, if you just need to generate ODT output, you can use DOC or DOCX file as a template. And then just save the output document in ODT format.

Best regards.

Thanks for help, I'll try this.

Max