Sign In  Sign Up Live-Chat

Merge with regions and Bookmarks

Last post 03-19-2008, 7:27 PM by lachlanaldred. 2 replies.
Sort Posts: Previous Next
  •  03-18-2008, 2:16 AM 118109

    Merge with regions and Bookmarks

    Hello,

    I'm trying to perform a merge-with-regions and there are some bookmarks inside my region.  I want to copy the bookmarks as well.  The reason I want to copy the bookmarks is that I need to use some application logic to delete selected instance of these internal bookmarks.

    The problem is that everything between my <<TableStart:MyRegion>> and <<TableEnd:MyRegion>> mergefields gets copied except for the nested bookmarks.

    Is there a way to copy bookmarks (with new names), or is there a better approach.

    Please help.

    Thanks in advance.


    This message was posted using Page2Forum from Mail Merge with Regions Explained - Aspose.Words for .NET and Java
     
  •  03-18-2008, 5:53 AM 118139 in reply to 118109

    Re: Merge with regions and Bookmarks

    Hi

     

    Thanks for your inquiry. You can rename bookmarks during MailMerge using MergeField event handler. For example see the following code.

     

    public void Test060()

    {

        //Create DataSourse

        DataTable table = new DataTable("myTable");

        table.Columns.Add("Field1");

        for (int i = 0; i < 10; i++)

        {

            DataRow row = table.NewRow();

            row[0] = "kjsdf;jshd;fkjs";

            table.Rows.Add(row);

        }

        //Open document

        Document doc = new Document(@"Test060\in.doc");

        //Add MergeField event handler

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

        doc.MailMerge.ExecuteWithRegions(table);

        doc.Save(@"Test060\out.doc");

    }

    //Index of bookmark

    int bookmarkIndex = 0;

    void MailMerge_MergeField_060(object sender, MergeFieldEventArgs e)

    {

        if (e.FieldName == "field1")

        {

            //Get parent node of mergefiled

            CompositeNode node = e.Field.Start.ParentParagraph;

            while (node != null)

            {

                //Get bookmarkstart collection

                NodeCollection starts = node.GetChildNodes(NodeType.BookmarkStart, true);

                if (starts.Count > 0)

                {

                    //Rename bookamrks

                    foreach (BookmarkStart start in starts)

                    {

                        start.Bookmark.Name = start.Bookmark.Name + bookmarkIndex.ToString();

                        bookmarkIndex++;

                    }

                }

                if (node.NextSibling.IsComposite)

                {

                    node = (CompositeNode)node.NextSibling;

                }

                else

                {

                    break;

                }

             }

        }

    }

     

    I hope this could help you. Also you can remove content from region using MergeFiled event handler.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  03-19-2008, 7:27 PM 118504 in reply to 118139

    Re: Merge with regions and Bookmarks

    Thankyou Alexey.
     
View as RSS news feed in XML