Bonjour,

En attendant le resultat des investigations de Cédric, voici une solution de 
contournement : 

Sub Main

        dim curSel as object
        dim selIndex as long

        curSel = thisComponent.currentSelection
        if (curSel.supportsService("com.sun.star.text.TextRanges")) then
                for selIndex = 0 to (curSel.count -1)
                        
traiterParagraphEnum(curSel.getByIndex(selIndex).createEnumeration())
                next selIndex
        end if

End Sub

sub traiterParagraphEnum(paraEnum as object)

        dim anElement as object

        while (paraEnum.hasMoreElements())
                anElement = paraEnum.nextElement()
                if (anElement.supportsService("com.sun.star.text.TextTable")) 
then
                        traiterTableau(anElement)
                elseif 
(anElement.supportsService("com.sun.star.text.Paragraph")) then
                        traiterParagraphe(anElement)
                else
                        'ne devrait pas arriver ? : ne rien faire
                end if
        wend

end sub

sub traiterTableau(unTableau as object)

        dim aCellName as string

        for each aCellName in unTableau.cellNames
                
traiterParagraphEnum(unTableau.getCellByName(aCellName).createEnumeration())
        next aCellName

end sub

sub traiterParagraphe(unParagraphe as object)

        dim textPortionEnum as object
        dim contentEnum as object

        textPortionEnum = unParagraphe.createEnumeration()
        while (textPortionEnum.hasMoreElements())
                contentEnum = 
textPortionEnum.nextElement().createContentEnumeration("com.sun.star.text.TextContent")
                while (contentEnum.hasMoreElements())
                        BoulotPourObjetUltime(contentEnum.nextElement())
                wend
        wend

end sub

Sub BoulotPourObjetUltime (Lobjet As Object)

        if Lobjet.getImplementationName="SwXTextEmbeddedObject" then
                if (Lobjet.embeddedObject.getImplementationName = 
"com.sun.star.comp.math.FormulaDocument") then
                        'Lobjet est une formule
                        print "formule détectée : " & Lobjet.Name
                end if
        end if
        
End Sub

Cordialement,
T. Vataire


----- Mail Original -----
De: "Agnès Simonet" <agnes.simo...@laposte.net>
À: prog@fr.openoffice.org
Envoyé: Mardi 27 Avril 2010 12:05:09
Objet: [prog] [writer]récupérer les formules dans un tableau

Bonjour,

Je cherche à récupérer les formules d'un document entier ou d'une 
sélection, pour pouvoir les modifier ensuite.
Les formules sont présentes dans le plain-texte et dans un tableau.

Pour le document je récupère comme ceci et tout va bien :
LeDocument=Thiscomponent
LesObjetsEmbedded=leDocument.getEmbeddedObjects
for i=0 to LesObjetsEmbedded.count-1
        LobjetEmbedded=LesObjetsEmbedded(i)
        BoulotPourObjetUltime (LobjetEmbedded)
next i  

Pour la sélection je procède ainsi :
LaSelection=ThisComponent.getCurrentSelection()
LesObjetsSel=LaSelection.getbyIndex(0)
LesObjetsTextContent=LesObjetsSel.createContentEnumeration("com.sun.star.text.TextContent")
 

        while LesObjetsTextContent.HasMoreElements
                LobjetTextContent=LesObjetsTextContent.NextElement
                BoulotPourObjetUltime (LobjetTextContent)
        wend    

Le sous-programme BoulotPourObjetUltime :
Sub BoulotPourObjetUltime (Lobjet As Object)
if Lobjet.getImplementationName="SwXTextEmbeddedObject" then
        if 
Lobjet.embeddedObject.getImplementationName="com.sun.star.comp.math.FormulaDocument"
 
then
        'Lobjet est une formule
        print "formule détectée : " & Lobjet.Name
        endif
endif
End Sub

Dans le cas de la sélection, les formules ancrées comme caractère dans 
le tableau ne sont pas "vues".
J'avoue que je ne comprends pas pourquoi.
Quelqu'un aurait-il une idée et -le rève- une solution ?

Le fichier exemple est disponible ici :
<http://agnooo.free.fr/pluxml/data/documents/pb/styles_formules/pb_formules_dans_tableau.odt>

Bonne journée
Agnès S.

---------------------------------------------------------------------
To unsubscribe, e-mail: prog-unsubscr...@fr.openoffice.org
For additional commands, e-mail: prog-h...@fr.openoffice.org


---------------------------------------------------------------------
To unsubscribe, e-mail: prog-unsubscr...@fr.openoffice.org
For additional commands, e-mail: prog-h...@fr.openoffice.org

Répondre à