Sign In  Sign Up Live-Chat

Mail Merge Regions

Last post 05-21-2008, 8:30 AM by alexey.noskov. 3 replies.
Sort Posts: Previous Next
  •  05-21-2008, 2:54 AM 127983

    Mail Merge Regions

    Dear Sir / Madam,

    I have an appointment letter formation in mail merge aspose. Based on some conditions which are string conditions few paragraphs will be seen otherwise not. For E.g If I belong to Senior Management Grade then I am going to be benefit with few Allowances which are mentioned in points. If I dont belong to Senior Management Grade I should not see that points at all. How can i check for String conditions in aspose.

    Can any one help in solving my problem.

    It is urgent.....

    Eagerly waiting for reply

    Thanks & Regards

    Geeta

     

     

     


    This message was posted using Page2Forum from Mail Merge with Regions Explained - Aspose.Words for .NET and Java
     
  •  05-21-2008, 3:15 AM 127987 in reply to 127983

    Re: Mail Merge Regions

    Hi

     

    Thanks for your request. I think that you can achieve this using MergeField event handler. For example see the following code:

     

    public void Test()

    {

        //Open template

        Document doc = new Document("in.doc");

        //Add MergeField event handler

        doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField);

        //Execute mail merge

        doc.MailMerge.ExecuteWithRegions(table);

        //Save output document

        doc.Save("out.doc");

     

    }

    void MailMerge_MergeField(object sender, MergeFieldEventArgs e)

    {

        if (e.FieldName == "myField")

        {

            //Here you can insert your condition logic

            //and do something with document

        }

    }

     

    Also see the following links for more information.

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/the-mergefield-event.html

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.reporting.mergefieldeventhandler.html

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-21-2008, 6:44 AM 128016 in reply to 127987

    Re: Mail Merge Regions

    Thanks for the help. But as i am new to aspose i am bit finding it diffiicult to handle the previous code. Can u send me some more links or sample code to use the Regions with aspose mail merge.

    Even i request you to send me the code in vb.net as i am into asp.net development not C# i am not having much idea.

    Waiting for the reply.

    Thanks & Regards

    Geeta

     

     

     

     
  •  05-21-2008, 8:30 AM 128037 in reply to 128016

    Re: Mail Merge Regions

    Hi

     

    Thanks for your request. Here is code example how you can perform mail merge with regions and use MergeField event handler. Also see attached template.

     

    Dim mCurrentName As String

     

    Sub Main()

     

        Dim lic As Aspose.Words.License = New Aspose.Words.License()

        lic.SetLicense("Aspose.Words.lic")

     

        Dim table As New DataTable("MyTable")

        table.Columns.Add("Name")

        table.Columns.Add("Option1")

        table.Columns.Add("Option2")

        table.Columns.Add("Option3")

        table.Columns.Add("Option4")

        table.Columns.Add("Option5")

        Dim noRep As Integer = 0

        For i As Integer = 0 To 4

            noRep = i

            table.Rows.Add(New Object() {"Alexey" & i.ToString(), "Option1", "Option2", "Option3", "Option4", "Option5"})

        Next

        'Open template document

        Dim doc As New Document("in.doc")

        'Add MergeField event handler

        AddHandler doc.MailMerge.MergeField, AddressOf HandleMergeField

        'Execute mail merge with regions

        doc.MailMerge.ExecuteWithRegions(table)

        'Save output document

        doc.Save("out.doc")

     

    End Sub

     

    Sub HandleMergeField(ByVal sender As Object, ByVal e As Aspose.Words.Reporting.MergeFieldEventArgs)

     

        'Here you can place your conditional logic

        If (e.FieldName = "Name") Then

            mCurrentName = e.FieldValue

        Else

            If (e.FieldName = "Option1" And mCurrentName = "Alexey0") Then

                e.Field.Remove() 'dont show Option1 if name is Alexey0

            End If

     

        End If

    End Sub

     

    Also see the following links.

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/mail-merge-with-regions-explained.html

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/execute-mail-merge-with-regions.html

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML