Unable to update field after mail merge using Aspose.Word (version : 9.4.0.0)

hi ,

we are using Aspose.word version: 9.4.0.0. with .Net 4.5 in our application and we are unable to update the fields in the document after mail merge.

i have attached a sample report where some of the fields are updating while others are not updating.

below is a sample code we are using to update the fields.

//Open the template document
AsposeWords.Document doc = new AsposeWords.Document(reportPath);
//merge the document template with the dataset
doc.MailMerge.ExecuteWithRegions(wds.DataSet);

string filepath = outputPath + Guid.NewGuid().ToString() + ".DOC";
doc.Save(filepath, AsposeWords.SaveFormat.Doc);

DocumentConversion.WaitForFile(filepath);
doc.UpdateFields();
doc.Save(filepath, AsposeWords.SaveFormat.Doc);

Note: if we select all (CTRL + A) the text of report output and right click and choose update fields option then all the fields are updated. But we are unable to update all the fields using Aspose library.

Hi Kamal,

Thanks for your inquiry. I
have tested the scenario and have managed to reproduce the same issue at
my side. Please check the attached image for the detail of this issue. For the sake of correction, I have logged this problem in our
issue tracking system as WORDSNET-10943. I have linked this forum thread
to the same issue and you will be notified via this forum thread once
this issue is resolved.

We apologize for your inconvenience.

Hi,

I am unable to change this post to public…
Please mark this post as public.

Hi Kamal,

Thanks for your inquiry. I have made this forum thread as public. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hi,

Thank you for update.

Could you confirm that latest Aspose.Word library also have this issue, as we are working with old version of same library(9.4.0.0)?

In addition, It will be helpful if you can let me know that your team is working on this issue and possible time when we can expect solution of this bug.

Thanks in advance.

Regards,
Kamal

Hi Kamal,

Thanks for your inquiry.

kamalkishore2014:
Could you confirm that latest Aspose.Word library also have this issue, as we are working with old version of same library(9.4.0.0)?

I tested this issue with latest version of Aspose.Words and have found that Document.UpdateFields does not update the formula field. See the attached image for detail.

kamalkishore2014:
In addition, It will be helpful if you can let me know that your team is working on this issue and possible time when we can expect solution of this bug.

Currently, this issue is under analysis phase. I am afraid we can not provide you any ETA at the moment. Once your issue is analyzed, we will then be able to provide you the ETA. Thanks for your patience.

The issues you have found earlier (filed as WORDSNET-10943) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi,

The updated version is working fine on updating the fields. But few issues are still not resolved.
Ex: Footer is still not updating.

I have attached 3 files for reference.

  1. SampleReport.doc is a sample mail-merge word report we used for mail-merge.
  2. Output.doc is an output of Microsoft.Word.Interop. We want to generate the same output using Aspose.word.
  3. mail-merge-sample-code.png is a sample code we have tried with.

I have tried with few of the solution provided on Aspose site but none of them is working.
we are looking for a unlink functionality of Microsoft.Word.Interop. The unlink method removes all the mail-merge code from word report so that plain text report can be send to client.

Hi Kamal,

Thanks for your inquiry. The mail merge fields inside the footer is not inside TableStart and TableEnd. In this case, you need to call MailMerge.Execute method as shown in following code example. I suggest you please read following documentation links for your kind reference.
https://docs.aspose.com/words/net/mail-merge-and-reporting/
https://docs.aspose.com/words/java/types-of-mail-merge-operations/

Please let us know if you have any more queries.

Document doc = new Document(MyDir + "SampleReport.doc");
DataTable table = new DataTable("BKFields");
table.Columns.Add("LOAN_SERVICER");
table.Columns.Add("POC_TYPE_OF_COLLATERAL");
table.Columns.Add("DOCUMENT_PAGE_FOOTER");
table.Rows.Add(new object[] { "Thomas Hardy", "86", "ASPOSE WORDS REPORT" });
doc.MailMerge.ExecuteWithRegions(table);
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;
doc.MailMerge.Execute(table);
doc.UpdateFields();
doc.Save(MyDir + "Out.doc");

Hi,

Thanks for the providing solution to update the fields. I was able to update all the fields in my document. But we also need to unlink the mail-merge code from our document.

I am again attaching the sample report and its output which we want to generate using aspose.

I have also attached the interop code which we used to unlink the mail-merge code in attachment for your reference.

Please provide the details about how to achieve the same functionality using aspose.

Hi Kamal,

Thanks for your inquiry. Please use the following code example to achieve your requirements. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "SampleReport.doc");
DataTable table = new DataTable("BKFields");
table.Columns.Add("LOAN_SERVICER");
table.Columns.Add("POC_TYPE_OF_COLLATERAL");
table.Columns.Add("DOCUMENT_PAGE_FOOTER");
table.Rows.Add(new object[] { "Thomas Hardy", "86", "ASPOSE WORDS REPORT" });
doc.MailMerge.ExecuteWithRegions(table);
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;
doc.MailMerge.Execute(table);
doc.UpdateFields();
FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldIf);
FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldFormula);
//Removes all fields of this collection from the document and from this collection itself. 
doc.Range.Fields.Clear();
doc.Save(MyDir + "Out.doc");

Hi,

Thanks for providing the solution to unlink the mail-merge code.
It is working fine for most of the reports. But I found 2 issues during unlinking.

  1. Page number in the footer is removed after unlinking.We want to keep the page number.
  2. Date is removed after unlinking. We want to display the date in our report. Date should also be converted in to plain text.

I have attached the SampleReport.doc and code sample for your reference.

Hi Kamal,

Thanks for your inquiry. In your case, I suggest you please do not call Range.Fields.Clear method. You can delete the unwanted fields from the document as shown in following yellow highlighted code snippet. The following highlighted code snippet removes the Set fields only.

For SIGN_DATE field, please use FieldsHelper.ConvertFieldsToStaticText method as shown in following code example.

Please let us know if you have any more queries.

Document doc = new Document(MyDir + "SampleReport.doc");
DataTable table = new DataTable("BKFields");
table.Columns.Add("LOAN_SERVICER");
table.Columns.Add("POC_TYPE_OF_COLLATERAL");
table.Columns.Add("DOCUMENT_PAGE_FOOTER");
table.Columns.Add("SIGN_DATE");
table.Rows.Add(new object[] { "Thomas Hardy", "86", "ASPOSE WORDS REPORT", DateTime.Now.Date });
doc.MailMerge.ExecuteWithRegions(table);
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedFields;
doc.MailMerge.Execute(table);
doc.UpdateFields();
FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldIf);
FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldFormula);
FieldsHelper.ConvertFieldsToStaticText(doc, FieldType.FieldRefNoKeyword);
foreach (FieldStart fStart in doc.GetChildNodes(NodeType.FieldStart, true))
{
    Field field = fStart.GetField();
    if (field.Type == FieldType.FieldSet)
    {
        field.Remove();
    }
}
doc.Save(MyDir + "Out.doc");

Hi,

Thanks again for the solution. But I found one more issue during the mail merge. Aspose mail-merge is not evaluating the COMPARE merge field correctly.

I have attached the SampleReport.doc and code.doc for reference.

Hi Kamal,

Thanks for your inquiry. I have tested the scenario and have not found the shared issue. Please check the attached output document.

Moreover, please use the MailMerge.CleanupOptions before calling the MailMerge.Execute method.

Could you please try again the same scenario with shared input document and let us know if you still face any issue along with following detail.

Please attach the output Word file that shows the undesired behavior.
Please
attach your target Word document showing the desired behavior. You can
use Microsoft Word to create your target Word document. I will
investigate as to how you are expecting your final document be generated
like.

Hi,

I missed one statement in my previous attachement of report.
I found that “*” is evaluated differently in aspose.

I have attached the updated report and the sample code I am using to update the report.
We need the else part but aspose is evaluating the if part instead (Please check the last if/compare statement).

please ignore the MailMerge.CleanupOptions we want to display the unmerged fields in the way it is implemented.

Hi Kamal,

Thanks for your inquiry. I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-11392. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi,

Apart from the wild card comparison there is an another issue we found in aspose.word mail-merge.

We have found that aspose is unable to mask the fields whereas interop.word does it successfuly.

Below mergefield display the last 3 characters of the SSN_FieldName successfully in interop.word but aspose mail-merge is display the whole field value along with preceding x.

{ MERGEFIELD SSN_FieldName # x###}

Hi Kamal,

Thanks for your inquiry. I
have tested the scenario using latest version of Aspose.Words for .NET 15.1.0 with following code example and have not found the shared issue. Could you please share your input document and SSN for which you are facing the issue? I will investigate the issue on my side and provide you more information.

Document doc = new Document(MyDir + "in.docx");
// Fill the fields in the document with user data.
doc.MailMerge.Execute(
new string[] { "SSN_FieldName" },
new object[] { 721071426 });
doc.Save(MyDir + "Out.docx");

Hi,

I have tried it with the Aspose.Word 15.1 version and I was able to reproduce the same issue.

I have attached the sample report and code for your reference.

We need to display the last 3-4 characters of the mergefield CLIENT_SSN.
Interop.word output for the same mergefield is 4454.
Aspose.word output for the same mergefield is x123654454.