Let's say I have this table:
If I do a table.Rows.MergeCells(0,2), the (empty) paragraphs from cells (1,1) and (1,2) will be appended to the merged cell.
The resulting cell looks something like this:
as I normally get if I merge celles in in a word processor.
I tried to remove the empty lines with Paragraph.Remove(), Paragraph.RemoveText(), and variations of Cell.Paragraphs.Remove(). But since Cell.Paragraphs is newed up based on the XML on every get, there is no use in manipulating this collection.
Luckily the DocXElement has read and write access to the Xml-property (XElement), which I used to work around the problem in my document-generator:
private static void RemoveEmptyParagraphsFrom(DocXElement cell)
var xml = cell.Xml;
foreach (var element in xml.Elements(Paragraph).Where(e => string.IsNullOrWhiteSpace(e.Value)).ToList())
Don't forget the ToList()-call, or else you will end up trying to modify the collection you are enumerating over.