[Writer] Iterate over the selected cells in a table

Creating a macro - Writing a Script - Using the API

[Writer] Iterate over the selected cells in a table

Postby Kovalevskaya » Tue Oct 22, 2019 10:01 pm

Hi everyone (again :D ). I have another little question for you guys . I'm using the LibreOffice Java API and I'm working
with tables. Handle tables it is a little bit confusing for me with the Java API so I'm in this situation: I need do some stuff
(searching for images to change its size) in each cell selected in the table but I don't know how obtain the cell range selected and
how iterate over that cell range.

¿How can I correctly iterate over the cells selected in a table using the Java API?

Thanks!
OpenOffice 5.1.6.2 Ubuntu 16.04
Kovalevskaya
 
Posts: 10
Joined: Fri Nov 30, 2018 8:04 pm

Re: [Write] Iterate over the selected cells in a table.

Postby Lupp » Wed Oct 23, 2019 11:18 pm

Kovalevskaya wrote:I have another little question...
"Little question"? Surely you are joking. And that's not actually a matter of what programming language you are using.

First you need to understand that images always are inserted into (silent) frame-shapes which never are technically inserted into a TextParagraph or into any cell of a TextTable. They are anchored in one or another way, and the objects they are anchored to don't know about. The shape object itself knows in what way and to what object (or page which is NOT an object) it is anchored.

Then: If you have selected a cellrange of a TextTable, you need to get the table itself as an object to be able to create and use TextTableCursor objects as needed ...

If you actually loop through the cells then, you (See above!) cannot find any images. Thus you would need in every case to loop in addition through the collection of all the shapes (the DrawPage of the TextDocument) and to test their anchors against the actual Cell for comparing the positions... Not so efficient!

A multiselection of images, on the other hand, is not supported in Writer...

Therefore:
Better loop once through the collection of shapes and create an array (or arrays) assigning the shapes (their indices probably) to the indices of all the TextTables (which are also collected per Writer document)...

You can then inspect that array to get the shapes being anchored to the cells (to a paragraph inside or "as character") of a range. Higher efficiency with this inspection you get if you sort that array first by cellnames and then (stable!) by tableindices. You have to pay with the sorting expense, of course for the advantage.
On Windows 10: LibreOffice 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2564
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Writer] Iterate over the selected cells in a table

Postby Kovalevskaya » Tue Nov 05, 2019 9:31 pm

Thanks Lupp, really that was not a little question XD.
OpenOffice 5.1.6.2 Ubuntu 16.04
Kovalevskaya
 
Posts: 10
Joined: Fri Nov 30, 2018 8:04 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests