Word Mail Merge with ASPOSE repeats header in table for all data rows

36 Views Asked by At

I have a C# MVC .NET application which uses ASPOSE to execute a mail merge. I have a table defined in the word document like this: enter image description here

I have the first row of the table defined as Repeat Heder Rows, as you can see in the image where Layout -> Data -> Repeat Header Rows is turned on when the fields in the first table row are selected.

When I run my application, and the mail merge executes, the resulting document looks like the following:

enter image description here

As you can see, the header information is being repeated for each dataset record. How do I get the heading to only print once at the start of the table? And how do I set this up so that if there are enough records in the dataset to force additional pages to be generated, to have the header generated at the start of each page.

This is the code that I use to generate the document:

Aspose.Words.Document masterTemplate = new Aspose.Words.Document(masterFilePath);
masterTemplate.FieldOptions.BarcodeGenerator = new CustomBarcodeGenerator();                    
masterTemplate.MailMerge.ExecuteWithRegions(dtMasterPetition);
masterTemplate.MailMerge.Execute(new string[] { "County",                                                                    
    "CaptionPetitioner",                                                                    
    "CaptionRespondent",                                                                     
    "Jurisdiction",                                                                     
    "IndexNo",                                                                     
    "TaxYear",                                                                     
    "ReturnDay",                                                                    
    "ReturnMonthYear",                                                                    
    "PetitionDate",                                                                    
    "FirmName",                                                                    
    "RespondentAddress1",                                                                    
    "RespondentAddress2",                                                                    
    "AlsoServeTitle",                                                                    
    "AlsoServeJurisdiction",                                                                    
    "AlsoServeAddress",                                                                    
    "AlsoServeCityStateZip",                                                                    
    "MPQRCode",                                                                    
    "FileAndSuffix",                                                                    
    "Attorney"}, 
new string[] { MailMergeData.PropCounty,                                                           
    MailMergeData.CaptionPetitioner,                                                           
    MailMergeData.CaptionRespondent,                                                           
    MailMergeData.Jurisdiction,                                                           
    MailMergeData.IndexNo,                                                           
    MailMergeData.TaxYear,                                                           
    MailMergeData.ReturnDay,                                                          
    MailMergeData.ReturnMonthYear,                                                          
    MailMergeData.PetitionDate,                                                          
    MailMergeData.FirmName,                                                          
    MailMergeData.RespondentAddress1,                                                          
    MailMergeData.RespondentAddress2,                                                          
    MailMergeData.AlsoServeTitle,                                                          
    MailMergeData.AlsoServeJurisdiction,                                                          
    MailMergeData.AlsoServeAddress,                                                          
    MailMergeData.AlsoServeCityStateZip,                                                          
    oMPQRCode.ToString(),
    FileAndSuffix,
    sAttorney});
                
MemoryStream masterpetitionMemory = new MemoryStream();
masterTemplate.Save(masterpetitionMemory, Aspose.Words.SaveFormat.Pdf);
docs.Add(masterpetitionMemory);
PdfFileEditor oEditor = new PdfFileEditor();
oEditor.Concatenate(docs.ToArray(), outStream);
outStream.Seek(0, SeekOrigin.Begin);

string GUID = Guid.NewGuid().ToString();
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(outStream);
fileName = fileName + "_" + GUID + ".pdf";
pdfDocument.Save(fileName);

Any help is greatly appreciated.

Thank you.

1

There are 1 best solutions below

3
Alexey Noskov On

In your template whole table is enclosed into TableStart/EableEnd merge fields, So the whole table is repeated for each record in your data source. To get the expected output, you should defile header row in a separate table like described here: Word mailmerge with Aspose from C# application and 2 tables