1
votes

I have a 10x1 table that I have generated in a Word table. Row 1 and row 5 have headings in them (for example). I need row 5 to be at the top of it's own page.

I have tried everything in order to insert a page break:

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);

None of the above work. It looks like the page breaks go outside the table. Obviously this must be possible as inside of work, pressing Ctrl+Enter inside of the table's cell inserts a break properly.

Anyone know how to do this?

1
Sorry to bump into this after ages but did you solve this issue? I am facing the same problem, page breaks go outside the table.Saurabh

1 Answers

0
votes

This code works for me with Word 2010 and 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;