Free Support Forum - aspose.com

Issue with Lead header and then subsequent headers

Trying to use aspose.words to create a document via merge. The merging works but the header is getting messed up. The first header is removed and the subsequent headers are repeated horizontally. Thoughts?

thanks,
Chad Boyer


Hi Chad,


Thanks for your inquiry. I would suggest you please read the following article on Controlling How Header and Footers Appear during appending documents:
http://www.aspose.com/docs/display/wordsnet/Controlling+How+Header+and+Footers+Appear

If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference along with input document. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Not sure if it applies because I already read it.


I am loading a document via aspose words and then calling mail merge on it. Then saving it.

Nothing fancy. But the first page header gets disappeared and then the other page headers gets repeated horizontally.

I will try the appending document fix but let me know if there is another way since currently I am doing it all via streams and it looks like the appending way requires the documents to be appended to each other to get the header data.

thanks,
Chad

Hi Chad,


Thanks for your inquiry.Could you please attach your input and output Word documents here for testing? I will investigate the issue on my side and provide you more information.

I have tried the code in that post and it just removes the header completely because there is no previous item to link to.


The code I am using:
global::Aspose.Words.Document doc = new global::Aspose.Words.Document(attachment.AttachmentTemplate.Transform.ReadMemory());

doc.MailMerge.Execute(dataRow);
if (dataSet.Tables.Count > 1)
for (int i = 1; i < dataSet.Tables.Count; i++)
doc.MailMerge.ExecuteWithRegions(dataSet.Tables[i]);

doc.MailMerge.DeleteFields();

I finish it with a doc.Save with an appropriate extension based on what the user selects.

The attachmentTemplate is the attached file to this post.

This has worked in the past with simpler logos but this particular logo in the header is giving us issues.

thanks.

A couple of extra points.


I cannot show the output data but the mail merge is just using a simple dataset with data from a loan.

The save output we are using for this example is pdf.

Hi Chad,


Thanks for sharing the details. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.1.0) from here and let us know how it goes on your side.

You are calling MailMerge.ExecuteWithRegions in your code multiple times (in a for loop) but there is no regions in your document. Please call MailMerge.Execute method and read following documentation links for your kind reference.
http://www.aspose.com/docs/display/wordsnet/How+to++Execute+Simple+Mail+Merge
http://www.aspose.com/docs/display/wordsnet/How+to++Execute+Mail+Merge+with+Regions

I have create a DataTable with dummy data and have tested your scenario. I have not found any issue with output PDF file. I have used the following code snippet. Please find the output PDF file in attachment.


<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Document(MyDir

  • “Test+Letter+with+headers.docx”);<o:p></o:p>

string[] fields = doc.MailMerge.GetFieldNames();

//Create DataTable for mail merge

DataTable dt = new DataTable();

foreach (string column in fields)

{

if (dt.Columns.Contains(column) == false)

dt.Columns.Add(column, typeof(string));

}

//Create three rows

for (int rows = 0; rows < 3; rows++)

{

object[] array = new object[dt.Columns.Count];

for (int i = 0; i < array.Length; i++)

{

array[i] = dt.Columns[i].ColumnName + "_" + i;

}

dt.Rows.Add(array);

}

doc.MailMerge.Execute(dt);

doc.MailMerge.DeleteFields();

doc.Save(MyDir + "Out.pdf");


If the problem still exist, please share following details.

What environment are you running on?
  • OS (Windows Version)
  • Architecture (32 / 64 bit)
  • .NET Framework version
  • Please supply us with the code from your application that is causing the issue. You may create DataSet/DataTable as shown in above code snippet.
  • Please supply us with the output PDF showing the undesired behavior

So the resolution we found was that the header was in a .dotx format and when we changed it to .jpg we got the same output file that you got. When we were doing it before the first page header was ignored and the other pages carried throughout.


thank you for your assistance.

Hi Chad,


Thanks for your feedback. It is nice to hear from you that you have found the resolution. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.