Ask Your Question
0

Delete 3rd row of all tables

asked 2019-07-01 11:01:54 +0200

Chris Vella gravatar image

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-07-02 08:17:31 +0200

pierre-yves samyn gravatar image

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

edit flag offensive delete link more

Comments

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

Chris Vella gravatar imageChris Vella ( 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?

pierre-yves samyn gravatar imagepierre-yves samyn ( 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.

Chris Vella gravatar imageChris Vella ( 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.

Chris Vella gravatar imageChris Vella ( 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.

pierre-yves samyn gravatar imagepierre-yves samyn ( 2019-07-02 16:48:06 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-07-01 11:01:54 +0200

Seen: 23 times

Last updated: Jul 02