We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GetMergeFieldNames - Is there a method returning array of real IWMergeField fields instead names only

Thread ID:

Created:

Updated:

Platform:

Replies:

142435 Feb 4,2019 02:11 PM UTC Feb 8,2019 11:56 AM UTC WinForms 6
loading
Tags: DocIO
Giacomo Barbieri
Asked On February 4, 2019 02:11 PM UTC

I've already asked for a Feature, but maybe someone else has already found a solution/workaround for my needs...
We have many different groups in our documents, where different variables with the same name are used -> so the field-name is not enough to identify a field inside the document !
Available methods:
/// Returns a collection of merge field names found in the document.
/// The string array which contains the name of all the merge fields name in the document.
public string[]GetMergeFieldNames();

/// Gets a collections of merge field names in the specified group.
/// A String that represents the name of the group.
/// The string array which contains the name of all the merge fields name in the specified group.
public string[]GetMergeFieldNames(string groupName);

QUESTION 1
Is it possible to retreive the list of fields inside a document as WMergeField?
QUESTION 2
Is it possible to have a method to pass a WMergeField instance and get the linked owner group (if any ) ?

Example of our document content, where a mergefield with the same name is used in different group (with different meaning):
Group1

«BeginGroup:ASSE»

Name: «Text:NAME»

Desc: «Text:DESC»

Type desc: «Text:TYPE_DESC»

«EndGroup:ASSE»


Group2

«BeginGroup:DIDX»

Name: «Text:NAME»

Extension: «Text:EXT»

«EndGroup:DIDX»





Dilli Babu Nandha Gopal [Syncfusion]
Replied On February 5, 2019 12:46 PM UTC

Hi Giacomo, 
 
Thank you for contacting Syncfusion support. 
 
At present, DocIO has direct API to get the merge field names from entire Word document or a specific group.  
 
QUESTION 1: Is it possible to retrieve the list of fields inside a document as WMergeField? 
No, direct API to get list of WMergeField instances inside a document. We can iterate the document elements and get the WMergeField instances. Please make use of below sample. 
 
QUESTION 2: Is it possible to have a method to pass a WMergeField instance and get the linked owner group (if any)? 
No, direct API to get the linked owner group fields for a specific WMergeField instance. We can get the owner group fields from list of WMergeField instances in a document. The immediate group start field before the specific WMergeField instance is its owner group start. The immediate group end field after the specific WMergeField instance is its owner group end. 

Could you please share us more specific details about your use case or purpose of getting WMergeField instances and its owner groups (What you are trying to do with WMergeField instances and its owner groups?). It will help us to validate your use case and provide appropriate solution. 
 
Regards, 
Dilli babu. 


Giacomo Barbieri
Replied On February 5, 2019 02:03 PM UTC

Thankks for your support, I'll try to explain better our request

We need to know which merge fields are not replaced giving information to the user -> so it's necessary to have the merge field "object/instance" not only the name, as we have the same merge field names in different groups. At the moment if a mergefield name is replaced in the document we cannot know the specific replaced field, so we have mergefield not replaced but no information shared with the user.

In addition to this we need to remove groups with no data, so we need information on mergefield's owner group -> so if all mergefields belonging to a group are not replaced -> it's possible to remove the group.


Please feel free to ask every additional data can help you to understand better our problem,
best regards
Giacomo




Giacomo Barbieri
Replied On February 6, 2019 03:39 PM UTC

What we need is a  Dictionary < string, List>> mergeFieldsDictionary, where
  • key is the group name - null or string empty in case of  no group nor table, at document level
  • value is the list of WMergeField defined in the group or document (but not in a group)
So we can do the following steps:
  1. start replacing variables group-by group
  2. replace variables defined at document level (no group nor table)
  3. collect document mergefield again
  4. the list of items remaining in the mergeFieldsDictionary are the variables that couldn't be replaced, so we can inform the user with specific warning

We've already implemented a method to collect all document WMergeField in a dictionary by name, how can I share this with you ?
This method is not enough as for example:
  • we have the same key for BeginGroup and EndGroup mergefield, without the information about which field is begin and which is end
  • we don't know which mergefields belongs to a group or another
The solution could be
  1.  have mergefield items (WMergeField) collected in a Dictionary < string, List>>, with a group with name null or "" (string.Empty) to identify document-level
  2. Call MailMerge replace execution for all group
  3. Call MailMerge.Execute replace management for mergefield in "document level" group only, to keep those not replaced but belonging to other group untouched
  4. Collecting all remaining mergefield in the same Dictionary < string, List>> you can have all not replaced mergefield for each group and document.



Dilli Babu Nandha Gopal [Syncfusion]
Replied On February 6, 2019 05:38 PM UTC

Hi Giacomo, 

Regarding it's possible to remove the group:
Yes, you can remove the empty group which contain empty merge fields by enabling RemoveEmptyGroup property.

Could you please provide us more details about what the not replaced merge fields actually meant in your requirement (“
variables that couldn't be replaced, so we can inform the user with specific warning”):
   1. Whether you need to get field name which not have DataColumn (column not defined) in the DataTable (Data structure used for mail merge)?
   2. Whether you need to get field name which contains empty value (empty string or null in data) for the merge field?

Also, please share the details about the data structure which used at your end for your requirement:
   1. Whether you have only one row for each data table ?
   2. Whether you have multiple rows (records) for each data table and need to get different field name and their group which not merged for each iterations.

Regarding
how can I share this with you ?
Could you please share us the below things from your end. This will be more helpful to check further on your requirement and provide you the appropriate solution at the earliest.
  1. Sample application or code snippets along with the template Word document.
  2. Dataset used at your end to perform mail merge.

Note: If you have any confidential data in your Word document and dataset, please replace with some dummy data and provide us the same. We just need your details to check on your working scenario.

You may upload the attachment directly in the forum, or mail it to support@syncfusion.com with forum Id as subject.
  
 

Regards, 
Dilli babu. 


Giacomo Barbieri
Replied On February 7, 2019 12:05 PM UTC

Good morning,

variables that couldn't be replaced, so we can inform the user with specific warning
These should be field names which not have DataColumn (column not defined) in the DataTable, but at the moment if field is present in DataTable but with null or string.Empty value, mergefield is not replaced by Syncfusion (I think this is a bug https://www.syncfusion.com/feedback/4625/mergefield-is-not-replace-removed-if-value-is-null). If we use " " (space) the mergefield is replaced...but we have a space char in output document that is not desired.
We have multiple rows for each DataTable: one DataTable represent a group and each DataTable column represent a mergefield to manage inside the group (for each row)


Document template with mergefield definition:

Group1 (PRIG)

«BeginGroup:PRIG»

Name: «Text:NAME»

Desc: «Text:DESC»

Note: «Text:NOTE»

«EndGroup:PRIG»


DataTable:
Text:NAME         Text:DESC
   AAA                     null
   BBB                     ""
   CCC                     ccc

Output

Group1 (PRIG)

Name: AAA

Desc: «Text:DESC» <-  Should be Desc: as column is present in DataTable, value null

Note: «Text:NOTE»


Name: BBB

Desc: «Text:DESC» <-  Should be Desc: as column is present in DataTable, value is "" (string.Empty )

Note: «Text:NOTE»


Name: CCC

Desc: ccc

Note: «Text:NOTE»


If the replacement for null or string.Empty will be fixed, maybe the need to have real WMergeFields instead names can be cancelled: our need to have WMergeField instance was to have the chance, if a mergefield is not replaced, to understand its belonging group to inform the user properly, but checking management better we found out that maybe it's not necessary as each mergefield in a group in case of multiple rows in related DataTable is "duplicated" for each row, so if we read the document before any management and collect all mergefield to use later for checks -> after replace of a group, the starting mergefield is no longer present as it's "cloned" for each row.... so the check we want to perform is not possible. We can check mergefield names belonging to a group versus DataTable column names to advice user.

I've sent our helper class in a private mail.


Dilli Babu Nandha Gopal [Syncfusion]
Replied On February 8, 2019 11:56 AM UTC

Hi Giacomo, 

We have created an incident (support ticket) for your queries where you can share the confidential information. Please log on to our support website to check for further updates  

Regards, 
Dilli babu. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;