Ask Your Question
0

writer macro for extending selection from Table to paragraph before and after table [closed]

asked 2020-01-03 11:51:57 +0200

torreone gravatar image

updated 2020-01-03 11:54:16 +0200

I use this code for selecting textTable in writer. How modify this macro for extending selection from this selected table to previous paragraph before table and next paragraph after table ? Using oVC.goDown(n, true) or oVC.goUp(n,true) not work.

  d=thisComponent
  t=d.textTables.getByName("Tabella1")
  oVC= d.currentController.viewCursor
  oCell=t.getCellByPosition (0,0) 
  oVC.gotoRange(oCell,false)         
  oVC.gotoEnd(True)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by torreone
close date 2020-01-03 13:51:02.048797

1 Answer

Sort by » oldest newest most voted
1

answered 2020-01-03 12:52:31 +0200

updated 2020-01-03 12:56:23 +0200

Try this code:

DefObj o
Sub ExtendTableSelection
  Dim oDoc, oTab, oCell, oVC, oEnum, oPar, oPrevPar, oNextPar
  oDoc = ThisComponent
  oTab = oDoc.getTextTables().getByName("Tabella1")
  oCell = oTab.getCellByPosition(0, 0) 
  oVC = oDoc.getCurrentController().getViewCursor()
  oVC.gotoRange(oCell, false)
  oVC.goUp(1, false) ' exit table and operate in its parent text '
  oEnum = oVC.getText().createEnumeration()
  ' Iterate through paragraphs (and tables) looking for the required table '
  ' Remember previous paragraph for the selection '
  Do While oEnum.hasMoreElements()
    oPar = oEnum.nextElement()
    If EqualUnoObjects(oPar, oTab) Then ' Found! '
      If Not (oPrevPar Is Nothing) And oEnum.hasMoreElements() Then
        oNextPar = oEnum.nextElement()
        oVC.gotoRange(oPrevPar, false)
        oVC.gotoRange(oNextPar, true)
      End If
      Exit Do
    End If
    oPrevPar = oPar
  Loop
End Sub
edit flag offensive delete link more

Comments

In addition to working great, you use solutions that I didn't know about and that can help me in other cases.

Thank you very much

torreone gravatar imagetorreone ( 2020-01-03 13:50:01 +0200 )edit

Please, if the answer solves the question click ✔.

m.a.riosv gravatar imagem.a.riosv ( 2020-01-03 15:30:24 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-03 11:51:57 +0200

Seen: 30 times

Last updated: Jan 03