Unexpected merge two tables together issue

Hi,

We would like to raise an issue. We have have found out that when we create two tables one after another they are merged into one table. This is visible when we open Word 2016. However in Word it’s possible to have two separate tables, one table after another with no spaces between them and that’s what we except as those tables can have different set up and when they are merged the don’t render correctly.

Here is a simple example where tables are merged

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

//build a 2x2 table
var table = builder.StartTable();
builder.InsertCell();
builder.Write($"Row 1, Column 1");
builder.InsertCell();
builder.Write($"Row 1, Column 2");
builder.EndRow();
builder.InsertCell();
builder.Write($"Row 2, Column 1");
builder.InsertCell();
builder.Write($"Row 2, Column 2");
builder.EndRow();
builder.EndTable();

//build a 2x3 table
var table2 = builder.StartTable();
builder.InsertCell();
builder.Write($"Row 1, Column 1");
builder.InsertCell();
builder.Write($"Row 1, Column 2");
builder.InsertCell();
builder.Write($"Row 1, Column 3");
builder.EndRow();
builder.InsertCell();
builder.Write($"Row 2, Column 1");
builder.InsertCell();
builder.Write($"Row 2, Column 2");
builder.InsertCell();
builder.Write($"Row 2, Column 3");
builder.EndRow();
builder.EndTable();

//save document
doc.Save("D:/output.docx");

Thanks,
Rafal

@acturisaspose This is expected behavior. In MS Word documents tables must be separated by a paragraph, otherwise they are concatenated in one table. Aspose.Words behaves the same way. So you should modify your code like this:

// ....
builder.EndTable();

// Insert a paragraph.
builder.Writeln();

//build a 2x3 table
var table2 = builder.StartTable();
//.....

Here is an example document which we got and want to replicate that has two tables (one after another one) and they are separate in MS Word 2016.
Tables.docx (18.0 KB)

@acturisaspose The tables are not merged if they have different properties. For example if add title, Aspose.Words does not merge the tables:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

//build a 2x2 table
var table = builder.StartTable();
builder.InsertCell();
builder.Write($"Row 1, Column 1");
builder.InsertCell();
builder.Write($"Row 1, Column 2");
builder.EndRow();
builder.InsertCell();
builder.Write($"Row 2, Column 1");
builder.InsertCell();
builder.Write($"Row 2, Column 2");
builder.EndRow();
builder.EndTable();

table.Title = "Table1";

//build a 2x3 table
var table2 = builder.StartTable();
builder.RowFormat.HeadingFormat = true;
builder.InsertCell();
builder.Write($"Row 1, Column 1");
builder.InsertCell();
builder.Write($"Row 1, Column 2");
builder.InsertCell();
builder.Write($"Row 1, Column 3");
builder.EndRow();
builder.RowFormat.HeadingFormat = false;
builder.InsertCell();
builder.Write($"Row 2, Column 1");
builder.InsertCell();
builder.Write($"Row 2, Column 2");
builder.InsertCell();
builder.Write($"Row 2, Column 3");
builder.EndRow();
builder.EndTable();

table2.Title= "Table2";

//save document
doc.Save(@"C:\Temp\out.docx");

However, MS Word in this case still shows the tables as a single table, though they are separate tables in the internal document representation:

<w:tbl>
	<w:tblPr>
		<w:tblCaption w:val="Table1" />
.......
</w:tbl>
<w:tbl>
	<w:tblPr>
		<w:tblCaption w:val="Table2" />
.......
</w:tbl>