Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MigraDoc Two Tables in one row

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!

like image 917
coding Avatar asked Dec 18 '22 23:12

coding


1 Answers

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);
like image 160
Uriel Carrillo Avatar answered Dec 21 '22 12:12

Uriel Carrillo