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?
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?
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
This macro deleted the first row and not the third even of the two tables that I had manually deleted the third row.
Strange: see removeByIndex (and I naturally tested the macro before proposing it)…
Do your tables have a particular structure?
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.
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.
Okay @ChrisVella thanks for the feedback. My generic procedure had to be adapted to this case indeed.