c# 互操作字 Rows.AllowBreakAcrossPages

c# Interop Word Rows.AllowBreakAcrossPages

我正在尝试使用 Interop Word 编写 table,但我不想允许跨页中断。所以我使用 Rows.AllowBreakAcrossPages 属性,但它对我不起作用,我不知道问题出在哪里?

有帮助吗?

 Word.Table table = rngDoc.Tables.Add(rngDoc, numFilasNueva, numColumnas);
        table.Rows.AllowBreakAcrossPages = (int)Microsoft.Office.Core.MsoTriState.msoFalse;

属性 AllowBreakAcrossPages 仅适用于单行。它无法将整个 table 保留在一页上。

如果 table 需要完整地保留在一页上,可以使用段落格式:KeepWithNext(table 的最后一段除外)和 KeepLinesTogether。 (最好使用样式,而不是直接格式化。)

或者,将 table 嵌套在另一个 table 中(一行,一列 = 一个单元格),并将 AllowBreakAcrossPages 设置为 False。

或者将 table 放在框架或文本框中。

如果 table 比一页长,最后两页不会分到另一页。

我做到了

table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
table.Rows.AllowBreakAcrossPages = (int)Microsoft.Office.Core.MsoTriState.msoFalse;
Word.ParagraphFormat pf = table.Range.ParagraphFormat;
pf.KeepWithNext = (int)Microsoft.Office.Core.MsoTriState.msoTrue;
pf.KeepTogether = (int)Microsoft.Office.Core.MsoTriState.msoTrue;