PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Sep 24, 2020 4:12 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed May 27, 2020 5:19 pm 
Offline

Joined: Mon May 18, 2020 6:44 am
Posts: 11
I have passed in some data into the DefineInvoice function from the database we are using using this code:

Code:
public void DefineInvoice(Document document,List<TicketView1> SampleTickets)


Looking into the data of SampleTickets we have key/value pairs for example such as this:

agreement_name: "Website Development 101"
billable_hrs: 9
customer_id: 36
customer_name: "Python Bank"
date_created: {4/29/2020 12:00:00 AM}...

and so forth. I have a table already created like so:

Code:
//define table
            Table table = section.AddTable();
       table.Borders.Width = 0.75;
           

            Column column = table.AddColumn(Unit.FromCentimeter(7));
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromCentimeter(2));
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromCentimeter(2));
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromCentimeter(2));
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromCentimeter(2));
            column.Format.Alignment = ParagraphAlignment.Center;
           

            //define header of table
            Row row = table.AddRow();
            row.HeadingFormat = true;
            Cell cell = row.Cells[0];
            cell.AddParagraph("Customer Name");
            cell.Format.Font.Bold = true;

            cell = row.Cells[1];
            cell.AddParagraph("Date Created");
            cell.Format.Font.Bold = true;

            cell = row.Cells[2];
            cell.AddParagraph("Description");
            cell.Format.Font.Bold = true;

            cell = row.Cells[3];
            cell.AddParagraph("Due Date");
            cell.Format.Font.Bold = true;

            cell = row.Cells[4];
            cell.AddParagraph("Billable Hours");
            cell.Format.Font.Bold = true;

            //define one row of invoice information
            row = table.AddRow();
            cell = row.Cells[0];
            cell.AddParagraph("Admin theme with psd project layouts");
            cell = row.Cells[1];
            cell.AddParagraph("1");
            cell = row.Cells[2];
            cell.AddParagraph("$26.00");
            cell = row.Cells[3];
            cell.AddParagraph("$5.98");
            cell = row.Cells[4];
            cell.AddParagraph("$31.98");

            //define another row of invoice information
            row = table.AddRow();
            cell = row.Cells[0];
            cell.AddParagraph("Wordpress Theme customization");
            cell = row.Cells[1];
            cell.AddParagraph("2");
            cell = row.Cells[2];
            cell.AddParagraph("$80.00");
            cell = row.Cells[3];
            cell.AddParagraph("$36.80");
            cell = row.Cells[4];
            cell.AddParagraph("$196.80");

            //define another row of invoice information
            row = table.AddRow();
            cell = row.Cells[0];
            cell.AddParagraph("Angular 9 and Node JS Application");
            cell = row.Cells[1];
            cell.AddParagraph("3");
            cell = row.Cells[2];
            cell.AddParagraph("$420.00");
            cell = row.Cells[3];
            cell.AddParagraph("$193.20");
            cell = row.Cells[4];
            cell.AddParagraph("$1033.20");

            //add invisible row as a space line to the table
            row = table.AddRow();
            row.Borders.Visible = false;

            //add the subtotal row
            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("Sub Total:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 3;

            //add tax row
            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("TAX:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 3;

            //add total
            row = table.AddRow();
            row.Cells[0].Borders.Visible = false;
            row.Cells[0].AddParagraph("TOTAL:");
            row.Cells[0].Format.Font.Bold = true;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[0].MergeRight = 3;


As you can see for my table headers such as "Customer name" I want to put that customer_name value into that cell. How would I do that? So far I have:

Code:
foreach (TicketView1 ticket in SampleTickets)
            {
                //customer_name
                //date_created
                //description
                //due_date
                //billable_hrs
            }


I am also learning C# as I go.. or I at least know most of the basics so this is tough for me. Any hints/tips or suggestions?


Top
 Profile  
Reply with quote  
PostPosted: Thu May 28, 2020 11:03 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3047
Location: Cologne, Germany
In the loop, call "AddRow()" to add a new row and then add the data to the cells in the column where the data should be.

MigraDoc sample with such a loop:
http://www.pdfsharp.net/wiki/Invoice-sa ... _Content_3

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Sat May 30, 2020 1:52 am 
Offline

Joined: Mon May 18, 2020 6:44 am
Posts: 11
I didn't see a loop inside the migradoc sample. Using the forEach loop along with what you said helped me solve the problem like this:

Code:
foreach (TicketView1 ticket in SampleTickets)
            {
                row = table.AddRow();

                cell = row.Cells[0];
                cell.AddParagraph(ticket.customer_name);

                cell = row.Cells[1];
                cell.AddParagraph(ticket.date_created.ToString("MM/dd/yyyy"));

                cell = row.Cells[2];
                cell.AddParagraph(ticket.description);

                cell = row.Cells[3];
                cell.AddParagraph(ticket.due_date.ToString("MM/dd/yyyy"));

                cell = row.Cells[4];
                cell.AddParagraph(ticket.billable_hrs.ToString());
            }


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group