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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
PROCEDURE InsererImage(_sDocumentChemin est une chaîne,LOCAL _sChaineARemplacer est une chaîne,LOCAL _sImageChemin est une chaîne,LOCAL _bAsLink est un booléen=Faux)
//---------------------------------------------------
//Ouverture du document
LOCAL
oServiceManager est un objet OLE dynamique
oDesktop est un objet OLE dynamique
oDocument est un objet OLE dynamique
sCheminFormaté est une chaîne
oServiceManager = allouer un objet OLE ("com.sun.star.ServiceManager")
oDesktop = oServiceManager>>createInstance("com.sun.star.frame.Desktop")
//Ne pas afficher le document
tArgs est un tableau de 1 objet Automation dynamique //Tableau de paramètres
tArgs[1]= oServiceManager>>Bridge_GetStruct("com.sun.star.beans.PropertyValue")
tArgs[1]>>Name = "Hidden"
tArgs[1]>>Value = True
//Formatage du chemin du fichier
sCheminFormaté = "file:///"+Remplace(_sDocumentChemin,"\","/")
//Ouverture du fichier dans OpenOffice Writer
oDocument = oDesktop>>LoadComponentFromURL(sCheminFormaté,"_blank",0,tArgs)
//---------------------------------------------------
//Recherche de la valeur et remplacement par l'image
LOCAL
sInfoImage est une chaîne
iLargeur est un entier
iHauteur est un entier
rLargeurMM est un réel
rHauteurMM est un réel
sGraphicURL est une chaîne
//Déterminer la taille de l'image en mm (à partir d'une taille en pixels)
sInfoImage = InfoBitmap(_sImageChemin)
iLargeur = Val(ExtraitChaîne(sInfoImage,2))
iHauteur = Val(ExtraitChaîne(sInfoImage,3))
Pixels_Vers_Mm(iLargeur,iHauteur,rLargeurMM,rHauteurMM)
rLargeurMM = rLargeurMM*100
rHauteurMM = rHauteurMM*100
sGraphicURL = "file:///"+Remplace(_sImageChemin,"\","/")
//----------------------------------------------
//Intégration de l'image dans le document
SI _bAsLink = Faux ALORS
oShape est un objet OLE dynamique
toProp est un tableau de 1 objet Automation dynamique
oProvider est un objet OLE dynamique
oShape = oDocument>>createInstance("com.sun.star.drawing.GraphicObjectShape")
oDocument>>getDrawPage()>>add(oShape)
toProp[1] = oServiceManager>>Bridge_GetStruct("com.sun.star.beans.PropertyValue")
toProp[1]>>Name = "URL"
toProp[1]>>Value = sGraphicURL
oProvider = oServiceManager>>createInstance("com.sun.star.graphic.GraphicProvider")
oShape>>Graphic = oProvider>>queryGraphic(toProp)
FIN
//----------------------------------------------
LOCAL
oSearch est un objet OLE dynamique
oFoundAll est un objet OLE dynamique
oFound est un objet OLE dynamique
oCursor est un objet OLE dynamique
oSearch = oDocument>>createSearchDescriptor()
oSearch>>SearchString = _sChaineARemplacer
oSearch>>SearchWords = OLETrue
oFoundAll = oDocument>>FindALL(oSearch)
POUR i = 0 _A_ oFoundAll>>Count -1
oFound = oFoundAll>>GetbyIndex(i)
oFound>>setString("")
oCursor = oFound>>getStart()
oImage est un objet OLE dynamique
oImage = oDocument>>createInstance("com.sun.star.text.GraphicObject")
SI _bAsLink = Vrai ALORS
oImage>>GraphicURL = sGraphicURL
SINON
oImage>>GraphicURL = oShape>>GraphicURL
FIN
//Anchor Type
//https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/TextContentAnchorType.html#AT_PARAGRAPH
//HoriOrient
//http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/HoriOrientation.html
//HoriOrientRelation
//https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/RelOrientation.html
//VertOrient
//http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/VertOrientation.html
//TextWrap
//https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/WrapTextMode.html
oImage>>AnchorType = 1
oImage>>TopMargin = 0
oImage>>BottomMargin = 0
oImage>>LeftMargin = 0
oImage>>RightMargin = 0
oImage>>BorderDistance = 0
oImage>>HoriOrient = 0
oImage>>VertOrient = 9
oImage>>Width = rLargeurMM
oImage>>Height = rHauteurMM
oImage>>SizeProtected = OLETrue
oFound>>text>>insertTextContent(oCursor,oImage,OLETrue)
FIN
SI _bAsLink = Faux ALORS
oDocument>>getDrawPage()>>remove(oShape)
FIN
//---------------------------------------------------
//Enregistrement et fermeture du document
LOCAL
mNoArgs est un tableau de 0 Variant
sDocumentCheminSav est une chaîne
sDocumentCheminSav = fExtraitChemin(_sDocumentChemin,fDisque+fFichier+fRépertoire)+HeureSys()+fExtraitChemin(_sDocumentChemin,fExtension)
sCheminFormaté = "file:///"+Remplace(sDocumentCheminSav,"\","/")
//Enregistrement du document (Enregister sous)
oDocument>>storeToURL(sCheminFormaté, mNoArgs)
//oDocument>>store()
oDocument>>Close(Vrai)
RENVOYER sDocumentCheminSav
CAS EXCEPTION:
Erreur(ExceptionInfo(errComplet))
RENVOYER Faux |
Partager