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

Free Support Forum - aspose.com

Set 'Allow row to break across pages' to false when using InsertHtml method

Hello Aspose Experts,

We are using DocumentBuilder.InsertHtml() method to make HTML a word document.
There is a table in html, here is my question:
Is there a property for HTML which can set the row of table to NOT ‘Allow row to break across pages’, (the default value is true, I want to set it false).
Is there an other method I can use?


After inserting the HTML into document, you can use RowFormat.AllowBreakAcrossPages property to achieve your requirement. We suggest you please read the following article.
Keeping Tables and Rows from Breaking across Pages

Thanks @tahir.manzoor.

Yep, I can set the property after inserting the html. However, I was trying to find a way to set the property BEFORE inserting html. Is there a way to accomplish that?

And also, if I am going to use RowFormat.AllowBreakAcrossPages property (after inserting html), I have to get the specific table firstly, Do you have any suggestion about how to get the specific table? Like adding some special ‘marks’ into the table html, and then we can use this mark to identify the table? Any suggestions? Thanks in advance!


You need to use this property after inserting the table (HTML).

You can insert the bookmark in the document and then insert the HTML. You can find the table using the inserted bookmark.

Moreover, we suggest you please read about Aspose.Words’ document object model from here:
Aspose.Words Document Object Model

@tahir.manzoor , Thanks for your response.
Maybe I was not clearly describe the problem.
Actually, what I am doing is like below.

  1. Generate html code according to the project logic. The html code contains many tables, (only some special type tables need to set RowFormat.AllowBreakAcrossPages).
  2. Using InsertHtml method to generate the word file.
  3. Using Node.GetChild(NodeType.Table, true) to find the specific table. And set RowFormat.AllowBreakAcrossPages.
    So I need to insert the bookmark by the html in phase 1. The question should be How to insert bookmark using html?


You may insert the bookmark as shown below in the HTML TD tag and get it using code snippet below:
<a name=“mybookmark”></a>

Bookmark bookmark = doc.Range.Bookmarks["mybookmark"];
Table table = (Table)bookmark.BookmarkStart.GetAncestor(NodeType.Table);

Once you get the table’s node, you can iterate over rows of table and use RowFormat.AllowBreakAcrossPages property.

You may also use second approach as shown below. Insert the HTML between BookmarkStart and BookmarkEnd nodes. Iterate over these nodes and get the table node. You can use Node.NextPreOrder method to get next node according to the pre-order tree traversal algorithm.

var doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(".... HTML....");

Bookmark bookmark = doc.Range.Bookmarks["bookmarkTable"];
//Iterate between BookmarkStart and BookmakrEnd nodes
//and get the Table node

@tahir.manzoor, Many thanks, you saved my time.
BTW, is there any document I can refer to about how to write ‘correct’ html?


It seems that your query is about writing HTML. There are many websites where you can find how to write correct HTML.