Anjello Joshua
Anjello Joshua

Reputation: 83

Novacode DocX Fixed Table Size in C#

How to have a fixed table size in C#? Like when I add the items, the still the same size as the template but the columns can be AutoFit. Thank you!

My Code:

Table tbl2 = doc.AddTable(15, 5);

tbl2.AutoFit = AutoFit.Contents;

tbl2.Alignment = Alignment.center;

tbl2.Rows[0].Cells[0].Paragraphs.First().Append("QUANITY").Bold().Font(new System.Drawing.FontFamily("Calibri")).Alignment = Alignment.center;
tbl2.Rows[0].Cells[1].Paragraphs.First().Append("UNIT").Bold().Font(new System.Drawing.FontFamily("Calibri")).Alignment = Alignment.center;
tbl2.Rows[0].Cells[2].Paragraphs.First().Append("DESCRIPTION").Bold().Font(new System.Drawing.FontFamily("Calibri")).Alignment = Alignment.center;
tbl2.Rows[0].Cells[3].Paragraphs.First().Append("UNIT PRICE").Bold().Font(new System.Drawing.FontFamily("Calibri")).Alignment = Alignment.center;
tbl2.Rows[0].Cells[4].Paragraphs.First().Append("TOTAL").Bold().Font(new System.Drawing.FontFamily("Calibri")).Alignment = Alignment.center;

My Table

P.S.: Is there any video tutorial that teaches Novacode DocX, can you give me the link. It really help us a lot! Thanks!

Upvotes: 2

Views: 4361

Answers (1)

Simon Price
Simon Price

Reputation: 3261

if you want to fix the size of the cells you need to do it like this.

Table signOfftbl = doc.AddTable(4, 2);
signOfftbl.Design = TableDesign.TableGrid;

signOfftbl.Rows[0].Cells[0].Paragraphs.First().AppendLine("");
signOfftbl.Rows[0].Cells[0].Width = 50m;
signOfftbl.Rows[0].Cells[1].Paragraphs.First().AppendLine("Accept advice and action recommendations");
signOfftbl.Rows[0].Cells[0].Width = 900m;

Upvotes: 2

Related Questions