Bonjour,
Le problème rencontré avec la fonction "ReplaceAll" et dû au fait que votre
curseur de navigation ne dispose pas de cette méthode : c'est le document qui
permet de faire appel à "ReplaceAll".
Pour savoir si un object dispose d'une méthode ou non, vous pouvez utiliser
l'outils Xray.
Ci-dessous vous trouverez un exemple d'utilisation de l'API de recherche qui,
je pense, correspond à ce que vous souhaitiez effectuer.
Sub Main
dim doc as object
dim rDesc as object
dim elem as object
doc = thisComponent
'on parametre le descripteur de recherche
rDesc = doc.createReplaceDescriptor
rDesc.searchString = "@"
'on recherche le premier element
elem = doc.findFirst(rDesc)
'si un element est trouvé
do while (not isNull(elem))
'et qu'il est dans une cellule
if (not isEmpty(elem.cell)) then
'on remplace le texte par le numéro de ligne
elem.string = getCellRow(elem.cell.cellName)
end if
'puis on recherche l'element suivant
elem = doc.findNext(elem, rDesc)
loop
End Sub
'récupère le numéro de ligne à partir d'un nom de cellule
function getCellRow(aCellName as string) as long
dim result as long
dim st as object
dim so as new "com.sun.star.util.SearchOptions"
dim searchRes as object
dim startOffset as long
st = createUnoService("com.sun.star.util.TextSearch")
so.algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
so.searchFlag = com.sun.star.util.SearchFlags.REG_NOSUB
so.searchString = "[:digit:]{1,}$"
st.setOptions(so)
searchRes = st.searchForward(aCellName, 0, 0)
if (searchRes.subRegExpressions = 1) then
startOffset = searchRes.startOffset(0)
result = cInt(mid(aCellName, startOffset + 1,
(searchRes.endOffset(0) - startOffset + 1)))
end if
getCellRow = result
end function
Cordialement,
T. Vataire
----- Mail Original -----
De: "Alan" <[email protected]>
À: [email protected]
Envoyé: Mardi 7 Juillet 2009 12h26:46 GMT +02:00 Harare / Pretoria
Objet: [prog] Re: Insertion texte dans tableau
Et voilà j'ai ma solution.
Pour résoudre le problème, je simule la fonction chercher/remplacer.
Je sélectionne au préalable la ligne de mon tableau.
Dim CellDest As Object
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 0
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 71680
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "(@)"
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1280
args1(17).Name = "SearchItem.Command"
args1(17).Value = 3
args1(18).Name = "Quiet"
args1(18).Value = true
For index_row = 1 to nb_rows - 1
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = "(" & index_row - 1 & ")"
CellDest = Table.getCellRangeByPosition(0, index_row, nb_col - 1, index_row)
Doc.CurrentController.Select(CellDest)
dispatcher.executeDispatch(Frame, ".uno:Paste", "", 0, Array())
CellDest = Table.getCellRangeByPosition(0, index_row, nb_col - 1, index_row)
Doc.CurrentController.Select(CellDest)
dispatcher.executeDispatch(Frame, ".uno:ExecuteSearch", "", 0, args1())
Next
Un grand merci à tous ceux qui ont pris du temps pour lire.
Et en espérant que ceci aidera quelqu'un d'autre.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]