Left and Top positions of table cells relative to page in MS Word - vba

I need to calculate the left and top coordinates of a table cell.
At work we have been developing an Add-In in VBA for Microsoft Word to turn Word documents into fillable PDF forms. All fields are to be inserted inside table cells, so it is the exact location of the table cells (left and top relative to the page) that are necessary for the placing of the data fields.
To get the vertical position of the top of a cell relative to the upper leftmost corner of the page we have tried:
Tables(n).Cell(row,column).Range.Information(wdVerticalPositionRelativeToPage)
The results exceed the table Top position by about 5 points at the top of the page. The excess is reduced as you go down the page. In cells located about the end of the page the result is spot on.
To get the horizontal position relative to the upper leftmost corner of the page we have tried:
Tables(n).Cell(row,column).Range.Information(wdHorizontalPositionRelativeToPage)
The results are incorrect. The results point to Left of the Table (not of the cell) plus about 3 points.
We have tried setting the table to Fixed Column Widths, and varying the zoom from 100% to fit to Window. No luck.
Any suggestions how to get the correct vertical (top) and horizontal (left) positions of a cell?

Related

Is There a More Efficient Way of Determining Whether a Table Row Spills Over Into the Footer Than Looping Through All Cells?

I'm currently using Microsoft Word 2016 VBA to programmatically set the AllowBreakAcrossPages setting so that if a row's contents overlaps the footer contents, I toggle the setting so that the row can break across pages. To solve this issue, I'm thinking about looping through all the cells of each table in the document and get the wdVerticalPositionRelativeToPage.Information of the last characters in each cell and comparing it to the footer's height relative to the page. If the last character's height is greater than the footer's, I set the row to break across pages. You can imagine that this is taking a while in a document that has many tables and cells. Is there a more efficient way to know if the row contents overlap the footer contents than looping through each cell in the row to see if a cell is causing the row to overlap the footer?
I tried using the row height property but discovered that if the HeightRule property of the specified row is wdRowHeightAuto then that means I can't access the row height via VBA.
I discovered that it's possible to use wdVerticalPositionRelativeToPage.Information with a row by row comparison of the prior and next rows like described in another posting - https://stackoverflow.com/a/14753231/4372244.
The only problem with that solution is that it doesn't work for the last row in a table or if it's the last row on a page.
Therefore, I'm examining a cell by cell solution.

Determining Left and Right Table Boundary Position

I need to know the left and right boundary position of a table. I tried various combinations of Selection.Information(wdHorizontalPositionRelativeToPage), but that appears to give the position of text within the table, and hence is dependent on cell padding and left/center/right justification.
I want the left and right table border position.
It seems this should be simple. For instance, the table knows where to draw it's boundaries.
You need to get the position of the table's range not the selection.
ActiveDocument.Tables(n).Range.Information(wdHorizontalPositionRelativeToPage) will give you the position for a specific table.
Selection.Tables(1).Range.Information(wdHorizontalPositionRelativeToPage) will give you the position for the table that contains the selection.

Getting data off of a Graph into a table

This is the yield calculator I'm working with
On the left of it is the input for the assay (crude oil) I'm getting in. It plots it on the graph, which has 6 horizontal lines at temperatures that are cutoffs for oils. Wherever the line crosses the horizontal Lines, I need to get that intersection point and put it in the table on the top right corner of the graph. Right now I'm just guesstimating the number rather than getting an exact one, and it's not automated. I've been trying to do something with VBA but am pretty lost.

How to scroll PyGTK ScrolledWindow to a certain row of a nested table?

I have a program in PyGTK which has a ScrolledWindow and a Table nested in it. The table rows can be of a different height. What I'm trying to find is a way to scroll the view so it begins from the selected row. I know how to move the scrollbar to a certain position using the scrolled_window.get_vadjustment().set_value(), but I do not know how to find the scroll position of the table rows.
Alternatively, maybe I'm using wrong widget and someone can point me to the right one? I'm trying to achieve the following behaviour: the screen shows the rows of a table, the top row is the currently selected object, when the user presses up or down buttons, the whole table scrolls down or up, so the previous or the next row becomes the top row.
Nevermind, I found a solution: you have to use the child widget get_allocation() function, which returns the bounding rectangle of a child widget relative to the scrolledwindow, so child.get_allocation().y is the answer to my own question.

listview items centered but left aligned when selected

I have a listview with a single column with values centered down every row. I'm just trying to find out what's causing the entries to get pushed to the left of the column everytime one of the entries is selected with a mouse or keyboard.
Thanks!