This project has moved and is read-only. For the latest updates, please go here.

Merging columns in a row creates line breaks inside that column

Aug 21, 2014 at 3:28 PM
I added a table with one row and 5 columns.

I then merged columns 2 to 5 using the following code. Problem is after merging it creates line breaks or you can say empty paragraphs. How do I remove those?
dataTable.Rows[0].MergeCells(1, 4);
Pic1 shows how it looks like after merging.

Pic2 shows how it should look like after merging.

How do I fix this problem?
Aug 22, 2014 at 1:12 PM
This is because paragraphs are getting inserted each cell automatically. When you merge the cells, the paragraphs are still there, one after the other in the now merged cell.

In my own projects, I don't want any of these empty paragraphs, so I've written the following method which I can call just before I call DocX.Save()
protected void RemoveEmptyParagraphsFromDocument( DocX document )
    document.Paragraphs.Where( p => String.IsNullOrEmpty( p.Text ) && p.Pictures.Count == 0 ).ToList().ForEach( p => p.Remove( false ) );
Aug 22, 2014 at 5:03 PM
Thanks I will try this.