Delete 3rd row of all tables

I've a long Writer document with many tables with three rows. I wish to delete the third row (and contents) of each of these tables. Is i possible automatically (find and replace?, macro?)

What would be the fastest way of doing this?

edit retag close merge delete

Sort by » oldest newest most voted

Hi

You can try:

Sub deleteRow()

dim oTables as object, oTable as object
dim i as integer

oTables = thiscomponent.TextTables

for i = 0 to oTables.count - 1
oTable = oTables.getByIndex(i)
if oTable.rows.count > 2 then
oTable.rows.removeByIndex(2, 1)
end if
next i

End Sub


Regards

more

This macro deleted the first row and not the third even of the two tables that I had manually deleted the third row.

( 2019-07-02 12:31:51 +0200 )edit

Strange: see removeByIndex (and I naturally tested the macro before proposing it)...

Do your tables have a particular structure?

( 2019-07-02 14:09:21 +0200 )edit

The structure of the tables is 2 columns and 3 rows. Actually I just realised that some tables have a 4th row and the first row spans the two columns. In this case it is always the last row that needs to be deleted - 3rd in case of a 3 row table or 4th when there are 4 rows.

( 2019-07-02 16:24:38 +0200 )edit

I changed the if oTable.rows.count > 2 then oTable.rows.removeByIndex(2, 1) to if oTable.rows.count > 3 then oTable.rows.removeByIndex(3, 1) and all 4th rows were deleted. The few tables with 3 rows I can take care myself manually.

( 2019-07-02 16:31:46 +0200 )edit

Okay @Chris Vella thanks for the feedback. My generic procedure had to be adapted to this case indeed.

( 2019-07-02 16:48:06 +0200 )edit