locked
MigraDoc populate table mvc.net RRS feed

  • Question

  • User-1664485818 posted

    Hi everyone,

    Can anyone explain to me how you would create a table using MigraDoc and then populate it using a foreach loop?

    Cheers,
    Brucey

    Friday, April 10, 2020 3:53 PM

Answers

  • User475983607 posted

    I have looked at the documentation, but I don't find it user friendly :-/ 

    Huh? the link in your previous thread is source code to populate a table cell by cell  row by row.  The kink in this thread is source code for different scenarios.  For a developer, documentation does not get more user friendly than source code. 

    Ok I can create the table, but I can't populate the table with the foreach loop...

    Any ideas?

    The loop logic above does not make sense.   The code indexes into row cells by the file name?   How's that possible?   Did you try the code pattern I provided in your other thread? 

    foreach(var string in ListOfItems)
    {
    	Row row = table.AddRow();
    	row.Cells[0].AddParagraph("Merge Right");
    	row.Cells[0].MergeRight = 1;
    	row.Cells[0].AddParagraph(item);
    	table.AddRow();
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 11, 2020 11:29 AM

All replies

  • User475983607 posted

    Hi everyone,

    Can anyone explain to me how you would create a table using MigraDoc and then populate it using a foreach loop?

    Cheers,
    Brucey

    See your other thread.  

    https://forums.asp.net/t/2165829.aspx?Working+with+Lists

    Honestly, it is up to you to learn the MigraDoc API.

    http://www.pdfsharp.net/wiki/PDFsharpSamples.ashx

    Friday, April 10, 2020 4:04 PM
  • User-1664485818 posted

    Thanks mgebhard,

    I have looked at the documentation, but I don't find it user friendly :-/ 

    Friday, April 10, 2020 4:20 PM
  • User-1664485818 posted

    Ok I can create the table, but I can't populate the table with the foreach loop...

    Any ideas?

                document.LastSection.AddParagraph("Files uploaded", "Heading2");
    
                Table table = document.LastSection.AddTable();
                table.Borders.Visible = true;
                table.TopPadding = 5;
                table.BottomPadding = 5;
    
                Column column = table.AddColumn();
    
                column = table.AddColumn();
    
                Row row = table.AddRow();
                foreach (var item in model.UploadedFiles)
                {
                    Cell cell = row.Cells[item.Filename];
                }

    Friday, April 10, 2020 5:39 PM
  • User475983607 posted

    I have looked at the documentation, but I don't find it user friendly :-/ 

    Huh? the link in your previous thread is source code to populate a table cell by cell  row by row.  The kink in this thread is source code for different scenarios.  For a developer, documentation does not get more user friendly than source code. 

    Ok I can create the table, but I can't populate the table with the foreach loop...

    Any ideas?

    The loop logic above does not make sense.   The code indexes into row cells by the file name?   How's that possible?   Did you try the code pattern I provided in your other thread? 

    foreach(var string in ListOfItems)
    {
    	Row row = table.AddRow();
    	row.Cells[0].AddParagraph("Merge Right");
    	row.Cells[0].MergeRight = 1;
    	row.Cells[0].AddParagraph(item);
    	table.AddRow();
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 11, 2020 11:29 AM
  • User-1664485818 posted

    Thanks mgebhard, yep I got it working 

    Saturday, April 11, 2020 11:38 AM