Problem with table

Good afternoon,

I am creating a word and I am following this example with the same code:

When I write in a cell, it creates a blank line and then writes the data to me in a strange way.
what can be happening?

This is the line for the first cell:

Table tableInicial = tables[0];
tableInicial.Rows[0].Cells[1].Blocks.Add(
    new Paragraph(document,
        new Run(document, dato.Codigo)
        { CharacterFormat = { Size = 10, FontName = "Arial MT", Bold = true } })) ;

In the image embedded, you can see the after and before:

Hi Alberto,

Can you send us your resulting DOCX file so that I can take a look at it?

Regards,
Mario

Of course, what email address should I send it to?

See our Contact page.

Hi,

I believe the problem was that the cell already had a paragraph.
However, it is expected that in that case, the spacing will come before the added paragraph, not after.

In those cases, the following should resolve the problem:

var cell = tableInicial.Rows[0].Cells[1];
var paragraph = cell.Blocks.OfType<Paragraph>().FirstOrDefault();
if (paragraph == null)
{
    paragraph = new Paragraph(document);
    cell.Blocks.Add(paragraph);
}

paragraph.Inlines.Add(
    new Run(document, dato.Codigo) { CharacterFormat = { Size = 10, FontName = "Arial MT", Bold = true } });

Regards,
Mario