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

Nested Mail Merge fields

Thread ID:

Created:

Updated:

Platform:

Replies:

103138 Apr 4,2012 03:41 PM UTC Apr 10,2012 01:39 PM UTC ASP.NET Web Forms (Classic) 5
loading
Tags: DocIO
Bill Barry
Asked On April 4, 2012 03:41 PM UTC

I have gotten nested mail merges to work but while building the template document the main issue I have is determining when to use BeginGroup vs TableStart.

In the meantime I was focusing on how to make the templates easier to make. To do so I thought I might export some version of the data to excel, so that you could build the mail merge and "test" it against an excel document.

Thus I started with a dataset like this:
table: root
Stores id
s1 0
s2 1

table: Manufacturers
Name root_id id
m1 0 0
m2 1 1
m3 1 2

table: Products
Name Price man_id
...

I took this dataset and generated a single table with the following columns:
BeginGroup:root
TableStart:root
Stores
id
EndGroup:root
TableEnd:root
BeginGroup:Manufacturers
TableStart:Manufacturers
Name
root_id
id
EndGroup:Manufacturers
TableEnd:Manufacturers
BeginGroup:Products
TableStart:Products
Name
Price
man_id
TableEnd:Products
EndGroup:Products

and one row of data so that the user could fake out a mail merge using the excel file as a data source.

When I opened Word and started a mail merge and chose this file for the datasource, the available columns were renamed to not have the colons in them: "BeginGroupManufacturers" (I assume this has something to do with how the process works in office). This meant that I had to manually change the field name every time I used it.

I was wondering if there was any way for me to change the separator so that the field name survives this process?


Ramkumar M [Syncfusion]
Replied On April 5, 2012 12:20 PM UTC

Hi Bill ,

Thank you for your interest in Syncfusion products.

To perform nested mail merge in a region the group start and end merge fields should be BeginGroup and EndGroup respectively. In a table the group start and end merge fields should be TableStart and TableEnd respectively. We have prepared the sample to clarify your doubt. Please find the sample for the same from the attachment. Try running the sample and let us know if this helps you.

Regarding your question about changing separator in field name is not possible because we used colon to separate the table name and BeginGroup. Could you please provide us the sample or explain in detail about your template creation method. So that we can analyze further on the exact need and provide you with the appropriate solution.

Please let us know if you have any other questions.

Regards,
Ramkumar




Sample_2e989c48.zip

Bill Barry
Replied On April 6, 2012 12:45 PM UTC

I modified your sample for this.

Steps to see what I am talking about (assuming office 2010):

1. run program
2. click Generate Data Fake
3. modify as desired, save and close
4. click View Template
5. Open Mailings ribbon
6. click Start Mail Merge > Step by Step Mail Merge Wizard
7. choose Letters
8. click Next: Starting document
9. choose Use the current document
10. click Next: Select recipients
11. choose Use an existing list
12. click Browse...
13. choose Sample\Data\MergeTemplateFakeData.xlsx
14. choose Sheet1
15. ensure First row of data contains column headers checkbox is checked
16. click OK
17. click OK again
18. in ribbon open Insert Merge Field dropdown

notice that the colons are removed from the merge field choices

19. after finishing click save (don't finish the mail merge in word)
20. click Generate and view the result



Sample_be9d2427.zip

Ramkumar M [Syncfusion]
Replied On April 9, 2012 05:24 PM UTC

Hi Bill,
Thank you for your update,
We can able to get your exact need, but removing Colon from the datasource fields is a feature of Microsoft office. As I said in my explanation about “Where to use BegingGroup and TableStart?”, in Nested Mail Merge, we used those terms as a keyword to identify mail merge area, so it is not possible to change that merge field name. It is better you can rename the field name by program instead of doing manually. We have prepared the sample to rename fields. Please find the sample for the same from the attachment. Try running the sample and let us know if this helps you.

Regards
Ramkumar




Sample_modified_23426dde.zip

Bill Barry
Replied On April 9, 2012 07:27 PM UTC

Can I visit the document like this (or will this break something that visiting the paragraphs separately from the tables will not)?


private static void AddColon(WMergeField field, string prefix)
{
string renameTo = prefix + ":";
if(!field.FieldCode.StartsWith(renameTo) && field.FieldCode.StartsWith(prefix))
{
field.FieldCode = field.FieldCode.Replace(prefix, renameTo);
}
}
private void RenameFields(WordDocument document)
{
foreach (var field in document.Visit().OfType())
{
AddColon(field, "BeginGroup");
AddColon(field, "EndGroup");
AddColon(field, "TableStart");
AddColon(field, "TableEnd");
}
}

...


public static class DocIOExtensions
{
public static IEnumerable Visit(this ICompositeEntity entity)
{
var entities = new Stack(new IEntity[] {entity});
while (entities.Count > 0)
{
var e = entities.Pop();
yield return e;
if (e is ICompositeEntity)
{
foreach (IEntity childEntity in ((ICompositeEntity) e).ChildEntities)
{
entities.Push(childEntity);
}
}
}
}
}



Ramkumar M [Syncfusion]
Replied On April 10, 2012 01:39 PM UTC

Hi Bill,
Thank you for your update,

We analyzed your code snippets; you can visit the document as like your code snippets, this will not break anything. But use "Contains" function instead of "StartsWith" function in "AddColon" function because Mail Merge Field Code starts with "MERGEFIELD"

Please let us know if you have any other questions.

Regards,
Ramkumar



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

or the page will be automatically redirected to 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

;