Novacode DocX固定表格大小用C#

时间:2016-09-14 06:43:48

标签: c# docx novacode-docx

如何在C#中使用固定的表格大小?就像我添加项目时一样,仍然和模板大小相同,但列可以是AutoFit。谢谢!

我的代码:

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。:有没有教过Novacode DocX的视频教程,你能给我链接吗?它真的帮助了我们很多!谢谢!

1 个答案:

答案 0 :(得分:2)

如果你想修复你需要这样做的单元格的大小。

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;