[Solved] Check if a document contains tables or images

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
elu
Posts: 1
Joined: Sat Aug 04, 2018 12:40 am

[Solved] Check if a document contains tables or images

Post by elu »

Given a document, is there a way to parse through it and determine if it contains tables or images?

Might be a easy question, but just need a general direction to head towards.

Thanks!
Last edited by elu on Sun Aug 05, 2018 8:31 am, edited 1 time in total.
OpenOffice 4.1.5 on MacOS 10.13
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Check if a document contains tables or images

Post by FJCC »

Getting a count of tables is easy. It is also easy to get a count of objects on the "DrawPage" of the document. These could be images or shapes, or, I suppose, other non-text content.

Code: Select all

oTables = ThisComponent.TextTables
print "Tables: ", oTables.Count

oDP = ThisComponent.DrawPage
print "Drawpage objects: ", oDP.Count
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Check if a document contains tables or images

Post by Lupp »

Also objects inserted as TextContent, OLE objects and TextFrames e.g. in addition to graphical Shapes are mostly gathered to the DrawPage. The only exceptions I know of are Paragraphs and TextTables.

Please point me to additional exceptions.
Last edited by Lupp on Sat Aug 04, 2018 12:07 pm, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
RoryOF
Moderator
Posts: 34613
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Check if a document contains tables or images

Post by RoryOF »

If I remember correctly (no time to look it up) Andrew Pitonyak gives such a document analysis macro in his book.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Check if a document contains tables or images

Post by hubert lambert »

Hello,

There is a dedicated method for images: getGraphicObjects.

Code: Select all

oImages = ThisComponent.GraphicObjects
print "Images: ", oImages.Count
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
Post Reply