PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
How to get values from table cells http://forum.pdfsharp.com/viewtopic.php?f=2&t=4139 |
Page 1 of 1 |
Author: | newbieCoder34 [ Sat May 30, 2020 1:57 am ] |
Post subject: | How to get values from table cells |
I am looking at the samples of migradoc invoice example but I am still not understanding it. I could possibly have more than one row of invoices, each with a cost. I then want the cost of all the invoice rows to be displayed into a table cell that says "total". For now I have only one row of data with a cost of "60.00." I looked into using GetValue() but not sure how to use it in my case. So I basically am figuring i need to somehow create a variable to where I am storing the selected cells value and then somehow be able to add it and other subsequent costs to the totals cell. Code: //define a row of data in the table
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()); } cell = row.Cells[5]; cell.AddParagraph("$60.00"); //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 = 4; cell = row.Cells[5]; //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 = 4; //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 = 4; } |
Author: | newbieCoder34 [ Mon Jun 01, 2020 4:42 am ] |
Post subject: | Re: How to get values from table cells |
I was able to figure it out with some help. I created a count variable called sum just before my forEach loop. Inside my forEach loop where i created a row and paragraph for the costs column, underneath I put the sum variable plus 60 since that's my dummy data for now. Later, where I created the totals row and in the totals cell, i put : Code: row.Cells[5].AddParagraph(sum.ToString("$0.00")); It seems to put my data inside that specific cell which is what I needed. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |