Free Support Forum - aspose.com

row.RowFormat.AllowBreakAcrossPages = False doesn't work

Hi,

I'm using the following method to build a table whose rows do not break across pages,

but the rows do break.

Any idea why?

Private Sub _buildTableByTableObj(ByVal doc As Document, ByVal rowNum As Integer)

Dim table As New Table(doc)

For i As Integer = 0 To rowNum - 1

Dim cell As New Cell(doc)

cell.CellFormat.Width = 6 * 72 '6"

cell.Tables.Add(_buildInnerTable(doc))

Dim row As New Row(doc)

row.RowFormat.Height = 0.4 * 72 '0.4"

row.RowFormat.AllowBreakAcrossPages = False

row.RowFormat.LeftPadding = 0.08 * 72

row.Cells.Add(cell)

table.Rows.Add(row)

Next

_setMainTableStyle(table)

Dim section As Section = doc.ChildNodes(0)

section.Body.InsertAfter(table, section.Body.Paragraphs(0))

End Sub

Thanks

RowFormat.AllowBreakAcrossPages = false; should prevent [the contents of] a single row from breaking across a page. If you are trying to keep two rows together so that they both appear on the same page then you need to use ParagraphFormat.KeepWithNext = true;

You may also need to use ParagraphFormat.KeepTogether = true; depending on what you are trying to accomplish. Experiment a little and I hope this helps.

John

How do I keep a table from breaking across pages?

Thanks

First, try to achieve the desired result in MS Word. Then find out what table/row formatting settings help to produce this result. Then you can apply these settings to produce the similar formatting in Aspose.Words.

Or you can just create the template illustrating what you are trying to achieve and attach it here. I will then compose a code snippet making the same formatting in Aspose.Words.

Here is some sample code, hopefully you can figure out how to use it from here. (This code is used while dynamically writing the tables using a DocumentBuilder, there are numerous other ways to use/do this).

int tableIndex = 0;
// foreach table
foreach ...
{

// some tables we want to try to keep entirely on a single page...
// if it is the first table and it is longer than a page we will end up with a blank page so...
// if this is the first table then ignore keeping it all together.

docBuilder.ParagraphFormat.KeepTogether = false;

if (tableIndex > 0)
{
docBuilder.ParagraphFormat.KeepTogether = true;
docBuilder.ParagraphFormat.KeepWithNext = true;
}

tableIndex++;
}

John

In word the "don't break across pages" setting is easy to set for a table:

"Table Properties"->at "Row" tab set "Allow rows to break across pages" to FALSE.

But the Table object of ASPOSE doesn't have this property, and I'm building a table not with the DocumentBuilder object, but with the Table object.

The attached document shows what I already achieved to produce with ASPOSE.

Each row of this table has a nested table of 3 rows,

the middle row of this table has a nested table of 4 rows,

of which the 3 bottom rows have a nested table of one row, that is shown as a bar.

Each row of the main table should not break across pages.

Thanks,

Ophir

Thanks for providing us a test document. I have played with it a little and discovered that indeed Row.RowFormat.AllowBreakAcrossPages property is not saved when document is saved. I have logged this defect as Issue #837. We will try to fix it within 1-2 weeks timespan.

Fixed in Aspose.Words 3.5.2 which is available for download:

http://www.aspose.com/Downloads/Aspose.Words/3.5.2.0/Default.aspx