I have a problem when merging word docs. If the template has text boxes or images, then the merging changes where they are placed. The text from text boxes is simply written on the page (left align) and images are also left aligned, regardless of their original position.
I am using the evaluation version of Aspose.Words while developing, can this be the reason? I was unable to find a list of diffenrences between the evaluation version and the full version, is there anything like that around here?
Thanks for Your attention
Jesper Dybdahl Hede
Evaluation version of Aspose.Words (without a license specified) provides full product functionality, but it injects an evaluation watermark at the top of the document on open and save and limits the maximum document size to several hundred paragraphs.
Please attach your source documents and document with problem. Then I will try to reproduce and solve this problem.
I have the two documents here, I hope it is understandable.
And the second doc
Thanks for additional information. I have tried to generate a document from your template using MailMerge and it seems that all works fine. Please provide me the code that you use to generate document.
Thanks for your reply. Over the weekend I found a bug in my code that created this fault. So the problem has been solved for this document. However, I have another problem that I first thought was related. Please see the documents attached. The merging seems to be going fine, but the text boxes are placed all wrong in Word. Is this something that can be fixed or should I just try to avoid text boxes?
I merge to HTML because I sometimes need to send the content directly in an E-mail, can this have something to do with the issue? Also, there are images on the page which also gets the left-allinement that they shouldn’t have. These have been removed for privacy issues.
Thanks for your request. I have tried to execute mail merge using your template and it seem that all works fine on my side. See the attachment. I have used the following code to execute mail merge.
DataTable dt = new DataTable("Table");
DataRow row = dt.NewRow();
row = "ABC Hoteller";
row = "Fornavn";
row = "Efternavn";
row = "+45 782209353242";
row = "crmdev_admin";
row = "admin";
Document doc = new Document(@"169_90955_jdh\in.doc");
Thank you for your reply. I’m happy to see that the setup of the template isn’t the problem. I have, however, at bit of a problem, since I do not have the template placed on the server, as your code suggests. The document template I use is placed as an annotation i Microsoft CRM 3.0. So the code I use for merging is this:
// Get file
string server = ConfigurationManager.GetCRMUrl();
byte rawdata = GetAttachment(ann.annotationid.Value, server);
_entityGuid = entityguid;
// Convert data to a memorystream and merge it with data from a stored procedure
MemoryStream memStream = new MemoryStream(rawdata);
Document doc = new Document(memStream);
DataSet data = GetDataSet(entityguid, storedProcedure);
if (data != null)
doc.MailMerge.MergeField += new MergeFieldEventHandler(InsertSpecialFields);
I hope it is readable. Can the use of a MemoryStream be the problem?
The InsertSpecialFields is a simple method that swaps the texts in the fields:
private void InsertSpecialFields(object sender, MergeFieldEventArgs e)
if (e.FieldName == “Field1”)
e.Text = “Text 1”;
else if (e.FieldName == “Field2”)
Please disregard the preceding post. I tried out a few things, and I got the problem solved.
The problem was that when saving the document to the server after merging I (again) used a MemoryStream. This messed up the formatting.
But I want to thank you very much for your quick and accurate replies.
<span style=“font-size: 12pt; font-family: “Times New Roman”;”>It is very nice that you
have found the solution independently.