We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Table separated from title

I am writing to an existing Word document using Aspose Words for .NET using C#. I manipulate the document by writing to bookmarks, adding rows to tables and insert text into table cells. The structure of the document is one large outer table of single celled rows with each row containing a table and each of those tables having a title just above it. Sometimes the title ends up on the bottom of a page with its corresponding table on the next page. I would like to ensure the table title is always on the same page as, at the very least, the top row of its table, but allow the table to span multiple pages. I have tried every combination, within Word, of ‘Keep with next’ and ‘Allow row to span multiple pages’ that I can think of but to no avail. From reading multiple forums, it seems I cannot achieve what I want using Word’s features.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Is there a way to do this programmatically with Aspose?

I appreciate your help.

Hi

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

Thanks for your request. Could you please attach your document? I will investigate this issue and try to help you. Maybe you should set Keep With Next for the title of table and for each row in table. Please try it out and attach your document for testing.

Best regards.

Thanks for your reply.

I have already tried your suggestion. This does indeed keep the whole table together with its title but I would like the table to split between pages. The only requirement is that the title is not stray, so at least one row of the table should be on the same page as it. Normally this is easy but because the table is in a cell of an outer table, it will 'keep with next' WITHIN the cell, regardless of whether the cell is allowed to 'break across pages'. Effectively, the inner table properties cannot 'see' the document pages, by virtue of the outer table's cell. That is my theory anyway.

If you look at the attached document you will see that I can achieve what I want with Table 2, because it is not within an outer table. To demonstrate this put some carriage returns before the table to force it onto the next page. You will see that the title sticks to the top row. With Table 1 however, because it is in an outer table, it doesn't behave the same. Both titles have 'keep with next' set.

I've read lots of forums and it really looks like this cannot be done within Word.

If I'm right, I need a programmatic solution.

Hope you can help....

Hi Russell,

Nice to hear from you again.

As far as I can tell you are talking about keeping the title row together with other rows on the same page, but you want this for a nested table.

I've tried this in MS Word and yes, it looks like it is not possible for nested table. For an outer table Keep With Next set on a paragraph keeps the title row together with the next row, but for a nested table it does not. There seem to be other features that MS Word ignores for nested tables. I tried Repeat As Header Row for a nested tabke and it does not work either.

MS Word probably has its reasons to do that or maybe its a bug. After all laying out tables into pages is a complex task.

What this means for you is no easy way out. It means you cannot achieve this behaviour just by setting formatting attributes.

Another way of doing that would be to "know" the layout position of each table on the page and detect situations when there is only one row left, but you cannot do that with Aspose.Words. There is no layout information in Aspose.Words.