How to examine a textTable cell and list any objects in it

Is there a way to take a given textTable cell and extract a list of objects contained in that cell via a macro? The cells in this table could contain a mixture of text, hyperlinks, and textTables. Thank you!

I’m using LibreOffice 24.2.6.2 (X86_64) on Ubuntu 22.04.5 LTS

Requested sample file
MT script test doc6.odt (34.8 KB)

Please upload an .odt type sample file here (with the text table and with some objects).

Added a sample file

There is a simple Table in your doc (4 columns x 5 rows) no hyperlinks, no nested Tables inside !

That is the sub table, the parent table has no visible border. Sorry for the confusion.

also useful : Development Tools

1 Like

There is enumaration for content of cell, and next enumeration to detect the parts in this content like hyperlinks. And I tried to test the property TableName to detect the inserted subtable → probably there is some other way how to detect the inserted subtable, but I had this idea.

Sub examineCells 'show info about text and hyperlinks and subtables in TextTable
	dim oDoc as object, oTable as object, oCell as object, sCell$, o as object, o2 as object, i%, sUrl$
	oDoc=ThisComponent
	oTable=oDoc.TextTables.getByName("CommonSkills")
	for each sCell in oTable.CellNames 'traverse all cells
		oCell=oTable.getCellByName(sCell) 'current cell
		for each o in oCell
			if o.PropertySetInfo.hasPropertyByName("TableName") then 'there is subtable
				msgbox("SUBTABLE: " & o.TableName, 48) 'subtable is with '!! icon in msgbox
			else
				for each o2 in o
					sUrl=o2.HyperlinkURL 'url from hyperlink
					i=msgbox("cell: " & oCell.CellName & chr(13) & "String: " & o2.String & chr(13) & "URL: " & sUrl , 4 + iif(sUrl<>"", 32, 0) ) 'hyperlink is with 'i' icon in msgbox
					if i=7 then stop 'pressed No
				next
			end if
		next
	next
End Sub

Good afternoon!
Instead of

if o.PropertySetInfo.hasPropertyByName("TableName") then 'there is subtable
  Msgbox("SUBTABLE: " & o.TableName, 48) 'subtable is with '!! icon in msgbox
else

we can use the same approach that is used when analyzing the text flow of a document:

if o.supportsService("com.sun.star.text.TextTable") Then
  msgbox("SUBTABLE: " & o.TableName, 48) 'subtable is with '!! icon in msgbox
elseIf o.supportsService("com.sun.star.text.Paragraph") Then

2 Likes

thankyou so much for this information