Multiple tables are being considered as a single table

Hi team,

I have two different tables in a Word document, but when I load the document and get the table list, both tables are considered as a single table. Why is this happening, and how can I get both tables separately?

Word Document :
Sample.docx (243.9 KB)

1 Like

@AlpeshChaudhariDev MS Word document format does not allow the table to follow each other. There must be a paragraph after the table, otherwise the tables are treated as a single table.

In your document however as I can see there are two separate tables:

Yes, that’s correct.

I apologize for providing incorrect information.

In both tables, the header format is set as HeadingFormat = false. Additionally, the page index for the first row of the first table is the same as the page index for the first row of the second table. I am unable to understand why this is happening.

I am using the LayoutCollector.GetStartPageIndex() function to get the row page index.

@AlpeshChaudhariDev Unfortunately, I cannot reproduce the problem on my side. I used the following simple code for testing:

Document doc = new Document(@"C:\Temp\in.docx");
LayoutCollector collector = new LayoutCollector(doc);

Table t1 = doc.FirstSection.Body.Tables[0];
Table t2 = doc.FirstSection.Body.Tables[1];

Console.WriteLine(collector.GetStartPageIndex(t1.FirstRow)); // Returns 1
Console.WriteLine(collector.GetStartPageIndex(t2.FirstRow)); // Returns 2

This is expected, the option is disabled for these rows:

I have this document please check in this document. Table index is 8 and 9. I got same page index for this tables.

Snippet :

NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
var t1Index = LayoutCollector.GetStartPageIndex(((Table)tables[8]).FirstRow);  // 5
var t2Index = LayoutCollector.GetStartPageIndex(((Table)tables[9]).FirstRow);  // 5

SampleDoc - Copy.docx (468.9 KB)

@AlpeshChaudhariDev I cannot reproduce the problem on my side. Your code returns 5 and 6 page indexes of the table. But the following fonts used in your document are not available on my side:

  • ‘KPMG Extralight’
  • ‘Univers for KPMG Light’
  • ‘Univers 45 Light’
  • ‘Univers for KPMG’
  • ‘Noto Sans Symbols’

The fonts are required to build document layout and calculate page count. If Aspose.Words cannot find the font used in the document, the font is substituted. This might lead into fonts mismatch and document layout differences due to the different fonts metrics. You can implement IWarningCallback to get notifications when font substitution is performed.
Please see our documentation to learn where Aspose.Words looks for fonts:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/