Hallo zusammen,
ich möchte ebenfalls einen Serienbrief in OOo erzeigen.
Als Grundlage dazu liefert mir ein anderes System eine Datenquelle. Nennen wir sie "C:\DataSource\Recipients.ods".
Wenn ich jetzt versuche diese Datei als Datenquelle zu registieren:
oo_sm ist ein ServiceManager-Objekt
str_filepath ist der Dateiname inkl. Verzeichnis
str_name ist der Name der Datenquelle unter der sie registiert werden soll.
Code: Alles auswählen
Function OoInstallDatasource(oo_sm As Variant, _
str_filepath As String, str_name As String) As Boolean
Dim oo_dc As Variant ' DatasourceContext
Dim oo_ds As Variant ' DataSource
Dim oo_dbdoc As Variant ' DatabaseDocument
Dim arr() As Variant ' registration parameter
' ### initialize ###
OoInstallDatasource = False
' ### register data source file ###
' get database context service
Set oo_dc = oo_sm.createInstance("com.sun.star.sdb.DatabaseContext")
' remove existing datasource named by str_name
' If (oo_dc.hasByName(str_name)) Then
' If OoRemoveDataSource(oo_sm, str_name) = False Then Goto terminate
' End If
' create new datasource instance
ReDim arr(0)
Set arr(0) = OoMakePropertyValue(oo_sm, "Overwrite", False)
Set oo_ds = oo_dc.createInstance()
Set oo_dbdoc = oo_ds.DatabaseDocument()
Call oo_dbdoc.storeAsURL(ConvertToURL(str_filepath), arr)
Call oo_dbdoc.store
oo_ds.URL = "sdbc:calc:" & ConvertToURL(str_filepath)
' register data source
Call oo_dc.registerObject(str_name, oo_ds)
' Call oo_dc.revokeObject(str_name)
' Call oo_dc.registerObject(str_name, oo_ds)
' ### return value ###
OoInstallDatasource = True
' ### terminate ###
terminate:
If Not (IsEmpty(oo_ds)) Then Set oo_ds = Nothing
If Not (IsEmpty(oo_dc)) Then Set oo_dc = Nothing
Exit Function
End Function
Das Problem ist jetzt, daß die Datei...
1. Jedesmal überschrieben wird. Die Datenquelle also komplett leer ist.
2. Die Datenquelle scheint´s nicht korrekt registiert wird, da ich sie nicht öffnen kann.
Gibt es eine Möglichkeit eine bestehende Datenquelle per Script zu registieren?
Gruß
Johnson