How to Get the Width of a Text Table Cell at the Cursor

Assume that the cursor is inside a Text Table in Writer. What I want is to get the width of the Cell the cursor is in using a macro. I can do this to get the cell itself:

Cursor = ThisComponent.getCurrentController().getViewCursor()
If NOT IsEmpty(Cursor.TextTable) Then
     oCell = Cursor.Cell

– but I can’t get any closer to what I want from there.

I’d be happy if I could just get the width of the appropriate column from the text table. You can see these values if you right-click on the table, select Table Properties and then select the Columns tab.

I’ve done a great deal of online searching but have found nothing. I’ve also used the DBG_Properties and DBG_Methods on a table, but didn’t see anything that would give me what I’m looking for.

It might be possible to get the width by inspecting the table’s TableColumnSeparators and then stepping through all the column values one at a time, but I was wondering if there was an easier way to do this. It certainly seems like the kind of information you’d want to be able to get at easily.

The tables in Writer are a little different. For a standard table, the columns have a separator position. So, just subtract these positions.

cursor = ThisComponent.CurrentController.ViewCursor
table = cursor.TextTable
tw = table.Width
last = 0
For Each c In table.TableColumnSeparators
	wc = tw * (c.Position / 10000000)
	MsgBox wc - last
	last = wc
Next

Definition from the famous book OOME_4_0.odt by A. Pitonyak:

A complex text table is a text table that is not simple. More accurately, a complex text table contains cells that have been split, or merged.

For complex text tables, a similar approach is used, but taking into account the row number of the cell.
Additional difficulties arise if the text table has the IsWidthRelative property True.

Thanks to both of you for your contributions. I suspected that I’d have to do something with the table’s TableColumnSeparators, just as elmau has shown. But as sokol92 points out, this gets much more complicated with more complex tables. It seems to me that getting the width of a cell directly may be the kind of thing to ask the LO team to implement. I wonder how you go about asking for this kind of improvement?

Incidentally, the reason why I need this is to determine whether a chess diagram can fit in the cell at the cursor. The chess diagram is inserted as a 10 x 10 grid of characters as can be seen below:

DiagramInCellSm

I have to be able to calculate the maximum font size that would allow the 10 lines of 10 characters to fit inside the available space without breaking up. I have to do this for a text table cell, a text frame, a text section column and the width of the page itself. The page and section column should not prove too difficult, but table cells are proving to be tough.

You could try This is the guide - How to use the Ask site? - #3 by Hrbrgr