Hi,
how can I get the Top position of a table in a document? NOT for a floating table! Is there a such way, like LayoutCollector/LayoutEnumerator for paragraphs?
The only way that I have found is to get the bottom of the PreviousSibling, but does it work for every type of nodes? And the calculation of the space between the table end the PreviousSibling?
You can estimate the Top position of Table in Word document by using the following code:
Document doc = new Document("C:\\Temp\\input.docx");
Table table = doc.FirstSection.Body.Tables[0];
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
layoutEnumerator.Current = layoutCollector.GetEntity(table.FirstRow.FirstCell.FirstParagraph);
layoutEnumerator.MoveParent(); // move to Line
layoutEnumerator.MoveParent(); // move to Cell
layoutEnumerator.MoveParent(); // move to Row
// Get the top position of first Row of Table
Console.WriteLine(layoutEnumerator.Rectangle.Top + " points or " + (layoutEnumerator.Rectangle.Top / 72) + " inches");