Bonjour,
Jovial a écrit :
Je me suis fait un fichier Bdd.odb
Je sais donc déclarer ma source en manuel dans Outil/Options....et tout
fonctionne bien
Je voudrai maintenant le faire par programmation
Le code que j'utilisais1.x ne fonctionne pas sur la 2.0
Existe t'il un exemple de code?
Voici un exemple de code pour la creation d'une source de données en
v2.0 sur un fichier CSV.
function CreationDatasource (directory As String, NomSource As String,
NomFichierSource As String) As Object
dim oContext as object, oNewSource as object, oDBContext As Object,
Reponse As variant
dim flatProp(7) as new com.sun.star.beans.PropertyValue
dim props(0) as new com.sun.star.beans.PropertyValue
oContext = createUnoService("com.sun.star.sdb.DatabaseContext")
oNewSource = createUnoService("com.sun.star.sdb.DataSource")
sUrl = ConvertToURL(directory)
props(0).Name = "Overwrite"
props(0).Value = True
oNewSource.databaseDocument.storeAsURL( NomFichierSource, props()) '
NEW STEP
flatProp(0).Name = "Extension"
flatProp(0).Value = "csv" ' string
flatProp(1).Name = "CharSet"
flatProp(1).Value = 0 ' long
flatProp(2).Name = "FixedLength"
flatProp(2).Value = True ' boolean
flatProp(3).Name = "HeaderLine"
flatProp(3).Value = True ' boolean
flatProp(4).Name = "FieldDelimiter"
flatProp(4).Value = chr(9) ' string
flatProp(5).Name = "StringDelimiter"
flatProp(5).Value = "" ' string
flatProp(6).Name = "DecimalDelimiter"
flatProp(6).Value = "." ' string
flatProp(7).Name = "ThousandDelimiter"
flatProp(7).Value = "," ' string
oNewSource.Info = flatProp()
oNewSource.databaseDocument.store() ' NEW STEP
oDBContext=createUnoService("com.sun.star.sdb.DatabaseContext")
Reponse=oDBContext.hasByName(NomSource)
If Reponse then
msgbox "La source de données " & NomSource & " existe déjà, ajout
impossible !"
exit Function
end if
oNewSource.URL = "sdbc:flat:" + directory
oNewSource.databaseDocument.store()
oContext.RegisterObject (NomSource, oNewSource)
CreationDatasource = oNewSource
End Function
Nous pouvons poursuivre la conversation sur [EMAIL PROTECTED]
Cordialement,
--
Florent Manens
[EMAIL PROTECTED]
http://www.starxpert.fr
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]