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. Image for the cookie policy date

MailMerge - Table

Hello,

Does it possible to find mailmerge fields on table ?
I wanna want adding mailmerge field inside a table.

Example: add a mergefield before TableEnd:TBL keyword

[IMG]http://img136.imageshack.us/img136/1874/sanstitrewk4.jpg[/IMG]

The GetMergeFieldNames() Of MailMerge Class Can find it.
But I want to know the section whose contains this fields...





6 Replies

BP Bhuvaneswari P Syncfusion Team June 3, 2008 10:18 AM UTC

Hi ioStreaM,

Thank you for your interest in Syncfusion products.

1. Add a mergefield before TableEnd:TBL keyword

Yes, it is possible to insert the Mergefield at the end of Mail merge table. We can't achieve this directly. For this we need enumerate all the section in the document, and then enumerate paragraphs in each section. In the paragraph we need to check the field type then insert the merge field in the desire place. Please refer the below code snippet to do so:


WordDocument document = new WordDocument(@"..\..\SalesInvoiceDemo.doc");
foreach (Entity ent in document.ChildEntities)
{
if (ent is WSection)
{
WSection section = ent as WSection;
foreach (WParagraph paragraph in section.Body.Paragraphs)
{
int k = 0;
foreach (ParagraphItem item in paragraph.Items)
{
k++;
//check whether item is mergefield
if (item is WField && (item as WField).FieldType == FieldType.FieldMergeField)
{
WMergeField field = item as WMergeField;
//Check the table Name and its Prefix
if (field.Prefix == "TableEnd" && field.FieldName == "Orders")
{
i = 1;
}

}
}
if (i == 1)
{
//Add new mergefield before the table end
ParagraphItem items = document.CreateParagraphItem(ParagraphItemType.MergeField);
WMergeField field = items as WMergeField;
field.FieldName = "NewField";
field.FieldType = FieldType.FieldMergeField;
field.TextFormat = TextFormat.Lowercase;
paragraph.Items.Insert(k-1,items as Entity);
i = 0;
}

}
}
}


Please refer the below sample which illustrate the above specified feature:

http://websamples.syncfusion.com/samples/DocIO.Windows/F74185/main.htm


2. Does it possible to find mailmerge fields on table ?

We have implemented two new methods to get the mail merge table names and to get the specified table fields names. Please refer the below code snippet:


//This will return the Tables in the document
string[] str=document.MailMerge.GetMergeGroupNames();

//This will return the specified group field names
string[] str1=document.MailMerge.GetMergeFieldNames(NameofTable);



These feature only implemented in our latest version Essential Studio Volume 2. We recommend you to upgrade our latest version.

Download Link :


http://www.syncfusion.com/downloads/latestversion/default.aspx


Unlock key:
If your Essential Studio license is current, you will be able to obtain the key to install this version from your account in DirectTrac. Otherwise, please contact your Syncfusion Sales Representative or e-mail salessupport@syncfusion.com.

Note: Image link that you have sent is not working.

Please try it and let us know if this helps you.

Best Regards,
Bhuvana




AD Administrator Syncfusion Team June 3, 2008 12:24 PM UTC

Great, i will try



AD Administrator Syncfusion Team June 3, 2008 12:57 PM UTC

Unfortunately my WMergeField class version does not have Prefix Property
Can have it by other way ?

http://img529.imageshack.us/img529/6167/sanstitrepk6.jpg



BP Bhuvaneswari P Syncfusion Team June 4, 2008 06:52 AM UTC

Hi ioStreaM,

Thanks for the update.

Yes, it is possible to check the filed TableEnd using the Text property of Field. Please refer the below code snippet to test it.


//check whether item is mergefield or not
if (item is WField && (item as WField).FieldType == FieldType.FieldMergeField)
{
WMergeField field = item as WMergeField;
string s = field.Text;
//Check the table Name and its Prefix
if (field.FieldName == "Orders" && s.Contains("TableEnd"))
{
i = 1;
break;
}




Here is the modified sample for your reference:

http://www.syncfusion.com/development/uploads/AddMergeField_f8e6acfd.zip


Note: We can't insert the field exactly before the TableEnd field. Because ParagraphitemType as Mergefield features are implemented in only in our latest. So we can't create a Paragraph item for mergefield and insert into the particular paragraph item. So In this sample I have inserted in the paragraph.

Please let me know if you have any concern.

Best Regards,
Bhuvana




AD Administrator Syncfusion Team June 4, 2008 07:35 AM UTC

It works fine.
But I must say my customer to upgrade his syncfusion version



BP Bhuvaneswari P Syncfusion Team June 9, 2008 05:56 AM UTC

Hi,

Glad to know that the workaround resolve the issue.

Please let me know if you have any other questions.

Best Regards,
Bhuvana


Loader.
Live Chat Icon For mobile
Up arrow icon