4

I am working on creating a report with MigraDoc that would be able to have 4 tables, 2 rows with 2 tables.

I have tried a number of different methods to accomplish this.

1- I have tried creating a leftIndent on the table.

table1.Format.LeftIndent = 7;

  1. I have tried creating a leftIndent on the rows of the table.

tables.Rows.LeftIndent = 5;

  1. I have also tried creating a table and inserting each table into a separate cell but I am not sure how to place the method to create the table within the table cell.

Any help or input that I can get on this would be much appreciated. Thank you!

coding
  • 71
  • 2
  • 10

2 Answers2

10

Following this post I was able to achieve this:

I had 4 tables like this:

        Table table = new Table();
        table.Borders.Width = 0.75;

        Column column = table.AddColumn(Unit.FromCentimeter(6));
        column.Format.Alignment = ParagraphAlignment.Left;

        Row row = table.AddRow();

        Cell cell = row.Cells[0];
        cell.AddParagraph("some value on first row");

        row = table.AddRow();
        cell = row.Cells[0];
        cell.AddParagraph("another value on second row");

        row = table.AddRow();
        cell = row.Cells[0];
        cell.AddParagraph("The value on third row");

Let's say we call those tables table, table2, table3 and table4.

We can insert a table inside a cell of a row on MigraDoc like this:

        Document document = new Document();
        Table TableContainer = new Table();
        Column columnC = TableContainer.AddColumn(Unit.FromCentimeter(7));
        TableContainer.AddColumn(Unit.FromCentimeter(7));

        Row rowC = TableContainer.AddRow();
        Cell cellC = rowC.Cells[0];
        cellC.AddParagraph("First Column");
        cellC = rowC.Cells[1];
        cellC.AddParagraph("Second Column");

        rowC = TableContainer.AddRow();
        cellC = rowC.Cells[0];
        cellC.Elements.Add(table);
        cellC = rowC.Cells[1];
        cellC.Elements.Add(table2);

        rowC = TableContainer.AddRow();
        cellC = rowC.Cells[0];
        cellC.Elements.Add(table3);
        cellC = rowC.Cells[1];
        cellC.Elements.Add(table4);

        document.LastSection.Add(TableContainer);
Uriel Carrillo
  • 171
  • 1
  • 8
0

I don't see a question. ;-)

Re 3: There is one known trick to add tables to tables: add a TextFrame to the Cell and add the Table to the TextFrame.

Cells cannot break to the next page, so the inner tables must be small enough to fit onto one page.