Sign In  Sign Up Live-Chat

RemoveEmptyParagraphs for TableStart / TableEnd

Last post 07-04-2008, 3:43 AM by alexey.noskov. 1 replies.
Sort Posts: Previous Next
  •  07-03-2008, 3:56 PM 134243

    RemoveEmptyParagraphs for TableStart / TableEnd

    Hi, Is it possible to have the RemoveEmptyParagraphs flag handle removing empty lines that contain nothing but a <<TableStart_MyRegion>> or <<TableEnd_MyRegion>>?

    For other merge fields, will it support removing blank lines caused by NULL values as well as blanks?

    Thanks.

     
  •  07-04-2008, 3:43 AM 134309 in reply to 134243

    Re: RemoveEmptyParagraphs for TableStart / TableEnd

    Attachment: Present (inaccessible)

    Hi

     

    Thanks for your inquiry. I think that you can use MergeField event handler to achieve this. For example see the following code and attached documents.

     

    public void Test253()

    {

        //Create some datasource

        DataTable myTable = new DataTable("myTable");

        myTable.Columns.Add("field1");

        myTable.Columns.Add("field2");

        myTable.Columns.Add("field3");

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

        {

            myTable.Rows.Add(new object[] { i.ToString(), "Some data" + i.ToString(), "Some text" + i.ToString() });

        }

     

        //perform mailmerge

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

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

        doc.MailMerge.ExecuteWithRegions(myTable);

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

    }

    void MailMerge_MergeField_253(object sender, MergeFieldEventArgs e)

    {

        if (e.FieldName == "field1")

        {

            Table parentTable = (e.Field.Start.GetAncestor(NodeType.Table) as Table);

            //Remove empty paragraphs before and after table

            parentTable.NextSibling.Remove();

            parentTable.PreviousSibling.Remove();

        }

    }

     

    Hope this helps.

     

    Best regards.


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