Free Support Forum - aspose.com

Mailmerge returns a blank page

Hello,

I’m elavuating the aspose word component and I still have one unresolved problem. Some times the merge creates a compleet blank word document. I think the problem is in the template document but I don’t know where to look for errors in the template file. Other template file are working fine with the aspose.word component.

Can somebody check my template file for possible errors?

Beste regards,
Perry

Hi Perry,

Thank you for considering Aspose.

Your template looks proper. I’ve tested it and it worked okay for me. So the problem is most likely lies in your data source. Please check that proper data is always passed to the merge engine, in particular, no empty DataTable is passed since this may exactly results in producing a completely blank document.

The data table is filled in correctly.

I did a test. I created another document dat looks excactly the same. It has the same mergefields. The first template file is merged correctly and the second returns a blank field.

Can somebody explain why this is the case.

I will attached the files in the next 2 posts

Best Regards perry

This is the file that works as it should work.

This is the old file which does not work…

Okay Perry, thanks for the attachments. Would you also please post a fragment of code you use for performing merge?

Dim lastError As String

Dim doc As Document

Try

doc = New Document(hoofdDoc)

'OpenStart a new mainDoc for the mail merge

doc.MailMerge.Execute(dataTb)

doc.Save(mergedDocPth)

Catch e As Exception

lastError = e.ToString

End Try

DmitryV wrote:
Hi Perry,

Thank you for considering Aspose.

Your template looks proper. I've tested it and it worked okay for me. So the problem is most likely lies in your data source. Please check that proper data is always passed to the merge engine, in particular, no empty DataTable is passed since this may exactly results in producing a completely blank document.


Did the postcode field also work when you tested it? It generates this error when I tested it.. Fout! Onbekende operator in voorwaarde. (Translated: Error! Unknown operator in precondition)

Perry

I’ve attached the resulting file. Here’s a code snippet I used for testing:

string[] fieldNames = doc.MailMerge.GetFieldNames();
string[] fieldValues = new string[fieldNames.Length];

for (int i = 0; i < fieldValues.Length; i++)
fieldValuesIdea = “POPULATED MERGE FIELD”;

doc.MailMerge.Execute(fieldNames, fieldValues);

As you can see, the generated document does not contain the error you have reported.

Just to make sure, are you using the latest version of Aspose.Word?

I’m using the evaluation version 3.1.0.0

Another question pops up by looking at the generated document.

Why does not all field contain the entire string “POPULATED MERGE FIELD”???

Perry

  1. Sorry but I can just repeat that a completely blank document may be produced by mail merge only in one case: if there is no records in the data source. So please double check it. Maybe the document you considered completely blank still had something? Could you please attach it?

    2. The issues related to merge fields seem to be caused by incorrect field evaluation. As I already said, I didn’t face that error you posted but this most likely has to do with evaluation of IF conditionals. Also, some fields indeed shows MERGE instead of POPULATED MERGE FIELD but this is evaluation again: for example, we end up with expressions like {IF POPULATED MERGE FIELD} and because POPULATED is not false, it returns MERGE.

    Please try to remake the document properly or (preferably) move the logic from the template to your code. Performing all these IF calculations before mail merge would hopefully resolve the issues.

What Dmitry meant is that Aspose.Word does not support field evaluation. Say if you have a formula in your document and you change the formula or one of the parameters it uses - Aspose.Word does not recalculate the result.

When the result is recalculated is up to MS Word when the user opens the document in MS Word next time. Most of the fields need Select All and Update in MS Word to show the updated result, but I think in some MS Word versions some of the fields are always recalculated on document open.

So in general our customers don’t use IF and other formula fields in their template documents because of the above. In your case it just seems the values of the formulas are updated, although keep this issue in mind.

Often such calculations can be moved into the query that produced the DataTable or into a DataView to wrap the DataTable. Another place to put calculations is a custom mail merge event handler.

We altered some template files and it seems to work correct now. Removing and adding the same merge field results in another value after the merge. We will have to check all are templates. We are using it for template files that are delivered by our customers. Each template has to be checked and if nessecairy altered, before using it. This is the only option we have. Moving the merge field evaluation to the code is out of the question. There are to many template files. We don’t want our application to know anything about Word specific issues.

Do you still have any outstanding issues you need us to look at?

For the time beeing not really. I will present my study to my supperior and hopefully we are going to buy some licence for aspose.word.

Thanks for all the help and I hope I will can ask any questions after buying the licence for further development.

Best Regards,
Perry

romank wrote:
When the result is recalculated is up to MS Word when the user opens the document in MS Word next time. Most of the fields need Select All and Update in MS Word to show the updated result, but I think in some MS Word versions some of the fields are always recalculated on document open.


This last question popped up:

Will this merge evaluation couse different problems with different version of MS Word or can I assume that if it the template is generated correctly with my version of MsWord that the customer will also see have a clean version of the generated document when opening it with another version of MSword?

Thanks,
Perry

As I said, we normally recommend customers to avoid using IF and formula fields in the templates populated with data because Aspose.Word does not evalute the fields and it raised my eyebrows when it looked like it was working okay for your document. I was going to test it more thoroughly and report back.

romank wrote:
I was going to test it more thoroughly and report back.


Please do because I really need to be sure that this feature works for our templates. Replacing the evaluation to the code will only be a suitable solution for worst case scenarios.

Thanks for your intrest.
Perry

Basically the way you want to use IF fields will not work with Aspose.Word. Please see my post in this topic for more info http://www.aspose.com/Forums/ShowPost.aspx?PostID=28948