Page 1 of 1

[Writer] Iterate over the selected cells in a table

PostPosted: Tue Oct 22, 2019 10:01 pm
by Kovalevskaya
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!

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

PostPosted: Wed Oct 23, 2019 11:18 pm
by Lupp
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.

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

PostPosted: Tue Nov 05, 2019 9:31 pm
by Kovalevskaya
Thanks Lupp, really that was not a little question XD.