1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Sub RecupBloc
MsgBox Recuperer_Bloc("AVIS :","Le projet tel")
End Sub
Function Recuperer_Bloc(DebBLoc as String,FinBloc As string)
'Declare variables
dim document as object
dim dispatcher as object
dim oDoc As Object
oDoc = thiscomponent
document = oDoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
'Créer un ViewCursor
oVC = oDoc.getCurrentController().getViewCursor()
oCursor = oVC.getText.createTextCursorByRange(oVC)
'Créer une recherche
desc = oDoc.createSearchDescriptor()
desc.setSearchString(DebBloc)
'Trouver le début du bloc
oDebBloc = oDoc.findFirst(desc)
'Si le résultat de la recherche n'est pas nul
if not isnull(oDebBloc) then
'Aller au début du bloc
oVC.gotorange(oDebBloc.End, false)
'Créer un TextCursor
oCursor = oVC.getText.createTextCursorByRange(oVC)
'Passer deux lignes (paragraphes)
oCursor.gotoNextParagraph (false)
oCursor.gotoNextParagraph (false)
'Trouver la fin du bloc
desc.setSearchString(FinBLoc)
oFinBloc = oDoc.findFirst(desc)
oVC.gotorange(oFinBloc.start,false)
'Etendre la sélection pour inclure tout le bloc
oCursor.GotoRange(oVC,true)
'Remonter d'une ligne (paragraphe)
oCursor.gotoPreviousParagraph (true)
Recuperer_Bloc = OCursor.String
end if
End Function |
Partager