Search code examples
novacode-docx

How to align 2 paragraphs side by side using Novacode DocX?


Using DocX I need to do something like this:

  1. A long text description.

Except I need the "1." to be a paragraph and the "A long text description" to be a paragraph. I cannot use a list for this.


Solution

  • late answer, but use a 2 column table with no visible borders

    some code i hacked out of my current thing. this makes a table and populates the cells with the contents of my cells, you'd just need to make a table, with 2 columns. and then iterate build a row with with cell[0] for the numeral, and cell[1] for the sentence

    doc.InsertParagraph("Table Title: " + (component).SubTitle, false, SubtitleStyle);
    var table = doc.AddTable(component.ColumnCount, component.RowCount);
    
    int rowcount = 0;
    foreach (DataCell datacell in component.TableData)
    {
        table.Rows[rowcount].Cells[0].Paragraphs.First().Append(rowcount+1);
        table.Rows[rowcount].Cells[1].Paragraphs.First().Append(datacell.CellValue);
        rowcount++;
    }
    doc.InsertTable(table);