Free Support Forum - aspose.com

Table breaking

Hi

Is there a way I can stop a table breaking over a page break. I would like to keep all the rows in a table on the same page (assuming the table is small enough, of course).

Thanks

Mike

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Could you please attach sample document for investigating?

I think that you can try using “Keep with next” (Select your table and do the following “Paragraph format”/”Line and page breaks”/”Keep with next” checkbox).

Or use the following code.

//Open document

Document doc = new Document(@"Test148\in.doc");

//Get table

Table wordTable = doc.FirstSection.Body.Tables[0];

//Get collection of paragraphs

NodeCollection paragraphs = wordTable.GetChildNodes(NodeType.Paragraph, true, false);

foreach (Paragraph par in paragraphs)

{

par.ParagraphFormat.KeepTogether = true;

}

//Save document

doc.Save(@"Test148\out.doc");

You can also try using AllowBreakAcrossPages property. See the following code.

//Open document

Document doc = new Document(@"Test148\in.doc");

//Get table

Table wordTable = doc.FirstSection.Body.Tables[0];

foreach (Row tabRow in wordTable.Rows)

{

tabRow.RowFormat.AllowBreakAcrossPages = true;

}

//Save document

doc.Save(@"Test148\out.doc");

Best regards

Hi

Thanks for that. It didn’t work - but then I realised you meant ‘par.ParagraphFormat.KeepWithNext = true;’ (not ‘KeepTogether’).

I know you were just testing me.

Thanks

Mike