如何使用Novacode DocX在表上设置“keep with next”属性?

问题描述 投票:2回答:1

在Word中,在段落>行和分页符下有一个属性“保持下一个”。我想知道是否有办法将此属性设置为使用Novacode DocX创建的表

c# docx novacode-docx
1个回答
0
投票

是的,使用KeepWithNext(true)设置表中每行中至少一个单元格的段落。如果要动态构建表,那么这很容易做到。

Novacode.Table t = doc.InsertTable(2, 3); // 2 rows; 3 columns

t.Rows[0].Cells[0].Paragraphs[0].Append("A1").KeepWithNext(true);
t.Rows[0].Cells[1].Paragraphs[0].Append("B1");
t.Rows[0].Cells[2].Paragraphs[0].Append("C1");
t.Rows[0].Cells[0].Paragraphs[0].KeepWithNext(true);

t.Rows[1].Cells[0].Paragraphs[0].Append("A2").KeepWithNext(true);
t.Rows[1].Cells[1].Paragraphs[0].Append("B2");
t.Rows[1].Cells[2].Paragraphs[0].Append("C2");
© www.soinside.com 2019 - 2024. All rights reserved.