Why "InsertParagraph(text)" adds one text line after and before of the text inserted?

Oct 28, 2014 at 11:36 AM
I am triying to add text to cells of a table, but the problem is that the text added comes in the table with two extra lineas (one before and one after), so I can't put a cell with one line of heigth.

This is my auxiliar function:

public static void FillCell(ref Table t, int r, int c, String text)
    Paragraph p = t.Rows[r].Cells[c].InsertParagraph(text);
    p.LineSpacingAfter = 0;
    p.LineSpacingBefore = 0;
    p.LineSpacing = 0;

Oct 29, 2014 at 8:32 AM
Is the table created using DocX or is it an existing table which already has text in its cells?
The cell will already have a paragraph if it was created using DocX (I think the same goes for a cell in a table in an existing Word document). So you could use " Paragraph p = t.Rows[r].Cells[c].Paragraphs[0]; " as well.

If you do need to add a paragraph, you could try using " p.SetLineSpacing(LineSpacingTypeAuto.None); ".