How to get the location of a TextTable object?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

How to get the location of a TextTable object?

Post by Lupp »

A variable got assigned a TextTable object belonging to a table contained somewhere in a Writer document.
It may have been created as a new instance and then inserted by InsertTextContent(). It may have been obtained from ThisComponent.TextTables or by enumeration of any Text object.

How can user code get a TextRange or TextCursor object or something else providing information about the location/position/ownership of the table in the document?
The TextTable may be inserted into the BodyText, into the Text of a TextFrame, or into the Text of a TableCell.
I cannot find a way to get the superordinated object.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2783
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to get the location of a TextTable object?

Post by JeJe »

oVC =ThisComponent.CurrentController.ViewCursor
if Not IsEmpty(oVC.TextTable) then
'do something with oVC.TextTable
end if
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3552
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: How to get the location of a TextTable object?

Post by Lupp »

Thanks for the reply!
Unfortunately this is not what I wanted to ask for.

I already have access to the TextTable object. This was not assumed to be based on the ViewCursor, but might also be.
But what can I do with that TextTable object? I can get its internal properties (number of rows ...) I can access any cell and work on its content... I can dispose the whole table.

Well. But if I want to insert the image of a bird or, simpler, a ruler shape behind the table I need the Text object the table once was inserted into and the position of the TextTable therein. Positions are given as objects of type TextRange regularly, and an anchored object has (hopefully) an Anchor supporting the respective service. A TextRange has an Anchor as it seems. Alas! The relevant properties of that Anchor I would need, in specific the Text property, are Null. (In case of AOO 4.1.5 I even get a crash if I attempt to inspect the Anchor object in the Basic IDE.)
In short: I cannot create a TextCursor based on the location of the table. How to do it?

If I search Andrew's texts I find subchapter 7.2.2 of "Useful Information", but there the Text object superordinated to the table is already known. However, a TextDocument can have an arbitrary number of Text objects: the primary (body) Text, the Text property of any TextFrame, The Text property of any Cell of any TextTable, the Text property of a Header or Footer... (Do you know more?)
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2783
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to get the location of a TextTable object?

Post by JeJe »

To position an image behind the table you can anchor the image to the first character in the first cell and set the position of the picture as 0cm from left and top and the picture wrap to in the background.

Macro to insert the picture at a text cursor position here:

viewtopic.php?f=5&t=58289
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2783
Joined: Wed Mar 09, 2016 2:40 pm

Re: How to get the location of a TextTable object?

Post by JeJe »

There's a note on the text table anchor here:
Note: The anchor of the actual implementation for text tables does not have a position in the text. Thus that anchor can not be used for some operation like attach for example or insertTextContent or other function that require the object to have a position in the text.

The reason why a text table still needs an anchor is that for example tables should be insertable via insertTextContent and that interface uses a parameter of that type.
https://www.openoffice.org/api/docs/com ... ntent.html
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply