Ask Your Question

Writer macro: is it possible to get the owner document object from a table object?

asked 2018-10-18 09:56:33 +0100

jfn gravatar image


I've got a writer document on which I programmatically add a table. So far so good. My question is: after the table is actually created and populated, using: oTable = oDoc.createInstance("")

Is there a way to retrieve the document owning object (in the example: the oDoc object) from the table object itself? This would avoid passing too many parameters to some subs I've got to write (only passing oTable without having to cascade passing the oDoc object). I've used XRay to check for various entry points, I've had a look a web resources about AOO and LibO API interfaces but to no avail. I guess I'm overlooking something here.

Thanks in advance for any help or suggestion.

Best regards,

Jean-Francois Nifenecker, Bordeaux

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-10-18 17:10:30 +0100

Lupp gravatar image

I never felt actual need to do this, but I considered the question as an abstract topic.
Many objects know where they belong to, and it's often necessary to access superordinated objects to get things right. You cannot copy a cellrange of a spreadsheet e.g. without accessing a sheet contained in the document and supporting the needed service. In no case I found a property reaching upwards to the document (or component) level. It may be possible to find a tricky way, to inspect all the components known to the StarDesktop and to find out which one is superordinate to the given object, but that's too complicated. ... I also didn't find a clear reason to do it this way. Probably we get an explanation by a developer.

Anyway: When you create an instance or get access to one, you will rely on a service doing it for you, and this service should belong to a specific document you know. If you defined a type like

Type entity
  super As Object
  thing As Object
End Type

and you create a variable and make assignments like

Dim myTable As entity
doc0 = ThisComponent
myTable.super = doc0
myTable.thing = myTable.super.TextTables(0)

you have a structure allowing to pass two levels you suppose to need in one parameter.

edit flag offensive delete link more


Hi Lupp, thanks for your thoughts. I know about using arrays or structures to pass parameters to subs or functions. Too bad there's no such property/method on a table object that can help getting to the owning document. I thought about using the Table.Anchor property which in turn exposes a .Text property but that seems to be a dead end, too.

jfn gravatar imagejfn ( 2018-10-18 19:10:30 +0100 )edit

The mentioned .Text actually was Null every time I inspected it. Thus the table object's anchor does not even point to the text object from which it can be obtained by enumeration. Did you once try to compare the positions of a table's .Anchor.Start with the position of any real anchor in the text? It fails. No useful message.
It's too annoying for me how understandig is blocked in this case. Hope I can forget the matter forever. It's only wasted time.

Lupp gravatar imageLupp ( 2018-10-18 20:50:56 +0100 )edit

Thanks for your time, anyway. Best,

jfn gravatar imagejfn ( 2018-10-18 22:12:57 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-10-18 09:56:33 +0100

Seen: 82 times

Last updated: Oct 18 '18