Merci pour ce code.
Permettez-moi d'exposer plus clairement mon projet pour créer un trombinoscope:
Au départ, j'ai
1) un dossier photos contenant les photos (type photos d'identités)(ex: Pierre Dupont.jpg , Jacques Durant.jpg, etc...
2) un document writer contenant la liste des nom des fichiers (sans extension)
Pierre Dupont
Jacques Durant
etc...
Mon projet est d'intégrer les photos dans le document, chaque photo dans un cadre créé et positionné par ses coordonnées x,y. La macro 'Trombinoscope' ci-dessous fonctionne bien, si ce n'est que, une fois la page pleine, une nouvelle page est ajoutée et les coordonnées des cadres réinitialisées (x=100, y=100), mais les cadres suivants de positionnent toujours sur la première page et non sur la page nouvellement créée.
Comment rendre la nouvelle page 'active'?
Merci de votre aide.
Ci-dessous l'intégralité du code:
Code : Tout sélectionner
sub Trombinoscope
Dim oDoc as Object, i as Integer, txt as String
oDoc = thisComponent
For i = 0 To oDoc.CurrentSelection.Count -1
If Len(oDoc.CurrentSelection.getByIndex(i).String) > 0 Then
txt = txt & oDoc.CurrentSelection.getByIndex(i).String & Chr(13)
End If
Next i
If Len(txt) > 0 Then MsgBox txt
Split1= Split(txt,chr$(13))
' xray split1
x=100:y=100
for i=0 to UBound(Split1)-1
if asc(Split1(i))<32 then fic = mid(Split1(i),2,len(Split1(i))) else fic = Split1(i)
creerUnNouveauCadre2(x,y, fic)
insereImageDanscadreExistant (fic,"I:\Mes documents\photos\"+fic+".jpg",35, fic)
x=x+3600
if x>17000 then x=100:y=y+6500 'Rangée suivante
if y>26000 then 'Ajouter une page et continuer sur la nouvelle page
x=100:y=100
oCurs = ThisComponent.getCurrentController().getViewCursor()
oDest = oCurs.getText()
oDest.insertControlCharacter( oCurs, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
oCurs.BreakType = com.sun.star.style.BreakType.PAGE_AFTER
end if
next
end sub
sub creerUnNouveauCadre2(posX, posY, name)
doc = thiscomponent
T = doc.Text
csst = com.sun.star.text
cadre = doc.createInstance("com.sun.star.text.TextFrame")
cadre.AnchorType = csst.TextContentAnchorType.AT_PAGE 'AT_PARAGRAPH ' const 0
cadre.Width = 3500
cadre.Height = 800
cadre.HoriOrient = csst.HoriOrientation.NONE ' const 0
cadre.HoriOrientPosition = posX
cadre.VertOrient = csst.VertOrientation.NONE ' const 0
cadre.VertOrientPosition = posY
cadre.Name = name
doc.Text.insertTextContent(T.Start, cadre, False)
' xray doc.Text
end sub
'*****************************************************************************************************
Sub insereImageDanscadreExistant(nomDuCadre as string, cheminDeLImage as string, tailleEnMm as integer, nomDeLimage as string)
' tailleEnCm <=> taille de l'image telle qu'elle aparaîtra dans le document
Dim monImage as Object
dim monTexte as object, monCadre as object
dim curseurCadre as object
dim graph as Object
dim proportion as integer
monCadre = thisComponent.getTextFrames.getByName(nomDuCadre)
monTexte = monCadre.text
curseurCadre = monTexte.createTextCursor
dim Prop(0) As New com.sun.star.beans.PropertyValue
Graph = CreateUnoService("com.sun.star.graphic.GraphicProvider")
Prop(0).Name = "URL"
Prop(0).Value = convertToURL(cheminDeLImage)
monImage = thisComponent.createInstance("com.sun.star.text.GraphicObject")
With monImage
.Graphic = graph.queryGraphic(Prop()) 'recupere le fichier image
.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
end With
monTexte.InsertTextContent(curseurCadre, monImage, False)
proportion = monImage.Height / monImage.Width
monImage.Width = tailleEnMm*100 ' largeur en 1/100 de mm
monImage.Height = monImage.Width * proportion *1.3
monTexte.insertString(curseurCadre, chr(13)+nomDeLimage, False)
end sub