C# 如何使用Word interop将分页符放在表中?
我有一个10x1表,我已经在一个单词表中生成了它。例如,第1行和第5行中都有标题。我需要第5行在它自己的页面顶部 为了插入分页符,我尝试了一切:C# 如何使用Word interop将分页符放在表中?,c#,ms-word,office-interop,C#,Ms Word,Office Interop,我有一个10x1表,我已经在一个单词表中生成了它。例如,第1行和第5行中都有标题。我需要第5行在它自己的页面顶部 为了插入分页符,我尝试了一切: table.Cell(row, 1).Range.InsertBreak(wdBreakType.wdPageBreak); table.Cell(row, 1).Range.Characters.Last.InsertBreak(WdBreakType.wdPageBreak); table.Cell(row, 1).Range.Collapse
table.Cell(row, 1).Range.InsertBreak(wdBreakType.wdPageBreak);
table.Cell(row, 1).Range.Characters.Last.InsertBreak(WdBreakType.wdPageBreak);
table.Cell(row, 1).Range.Collapse();
table.Cell(row, 1).Range.InsertBreak(WdBreakType.wdPageBreak);
以上都不起作用。看起来分页符超出了表格的范围。显然,这必须是可能的,因为在工作的内部,在表格单元格的内部按Ctrl+Enter可以正确插入中断
有人知道如何做到这一点吗?此代码适用于我的Word 2010和VS 2010:
Word.Application app = new Word.Application();
var doc = app.Documents.Add();
var tbl = doc.Tables.Add(doc.Range(), 10, 2);
tbl.Borders[Word.WdBorderType.wdBorderHorizontal].LineStyle = Word.WdLineStyle.wdLineStyleSingle;
tbl.Borders[Word.WdBorderType.wdBorderHorizontal].Color = Word.WdColor.wdColorDarkRed;
tbl.Borders[Word.WdBorderType.wdBorderVertical].LineStyle = Word.WdLineStyle.wdLineStyleSingle;
tbl.Borders[Word.WdBorderType.wdBorderVertical].Color = Word.WdColor.wdColorDarkRed;
tbl.Borders[Word.WdBorderType.wdBorderTop].LineStyle = Word.WdLineStyle.wdLineStyleSingle;
tbl.Borders[Word.WdBorderType.wdBorderTop].Color = Word.WdColor.wdColorDarkRed;
tbl.Borders[Word.WdBorderType.wdBorderBottom].LineStyle = Word.WdLineStyle.wdLineStyleSingle;
tbl.Borders[Word.WdBorderType.wdBorderBottom].Color = Word.WdColor.wdColorDarkRed;
tbl.Cell(6, 1).Range.InsertBreak(Word.WdBreakType.wdPageBreak);
app.Visible = true;
doc = null;
app = null;
很抱歉在很久以后遇到这个问题,但是你解决了这个问题吗?我也面临着同样的问题,分页符超出了表格的范围。