How to get the location of a TextTable object?

Creating a macro - Writing a Script - Using the API

How to get the location of a TextTable object?

Postby Lupp » Fri Oct 19, 2018 12:40 pm

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 6.1 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Let's create a powerful UFO: United Free Office!
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2101
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

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

Postby JeJe » Fri Oct 19, 2018 2:40 pm

oVC =ThisComponent.CurrentController.ViewCursor
if Not IsEmpty(oVC.TextTable) then
'do something with oVC.TextTable
end if
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 287
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby Lupp » Fri Oct 19, 2018 4:41 pm

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 6.1 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Let's create a powerful UFO: United Free Office!
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2101
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

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

Postby JeJe » Fri Oct 19, 2018 8:09 pm

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:

https://forum.openoffice.org/en/forum/v ... =5&t=58289
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 287
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby JeJe » Sun Oct 21, 2018 11:21 am

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
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 287
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 12 guests