(Question reopened.)
TextTableCursor
objects are poorly equipped, and to work with TextTable
objects based on the API often seems to be a game of chance.
I had the given question in mind more than once, and nowhere found a ready-made solution. Recently I again stumbled into that donkeywork, and actually I managed to learn a bit more. The progress allowed me to also find a solution for this question.
Accepting a “dirty but not at all quick” approach, I can now retrieve the TextTable from a TextTableCursor! Wow!
Funny code:
Function getTextTableFromSelection(pDoc As Object, Optional pSel As Object)
Dim tT As Object
getTextTableFromSelection = tT
On Local Error Goto fail
cCtrl = pDoc.CurrentController
oldSel = pDoc.CurrentSelection
If IsMissing(pSel) Then pSel = oldSel
If pSel.supportsService("com.sun.star.text.TextTableCursor") Then
wasCur = True
splRgN = Split(pSel.RangeName, ":")
wasSingle = (Ubound(splRgN)=0)
tlCellN = splRgN(0)
pSel.gotoCellByName(tlcellN, False)
cCtrl.select(pSel)
tRg = pDoc.CurrentSelection(0)
Else
tRg = pSel(0)
End If
textTable = tRg.TextTable
If NOT IsObject(textTable) Then textTable = tT
getTextTableFromSelection = textTable
fail:
cCtrl.select(oldSel)
If wasCur AND wasSingle Then
fr = cCtrl.Frame
dh = CreateUnoService("com.sun.star.frame.DispatchHelper")
dh.executeDispatch(fr, ".uno:EntireCell", "", 0, Array())
End If
End Function
Sub tryIt()
doc = ThisComponent
sel = doc.CurrentSelection
h = getTextTableFromSelection(doc, sel)
End Sub
With a lot of dirty tricks I might also be able to get the document from the TextTableCursor (or any selection in the doc), but I didn’t do that. To know the document is necessary to be able to use the CurrentController, which is needed for …
See yourself!