Mit der o.a. Beispieldatei und folgendem Code klappt es (es fehlt noch die Ausgabe der SQL-Abfrage nach "Tabelle3" und die dynamische Bestimmung des Datenbereichs):
Code: Alles auswählen
' 2008-08-04
CONST DATEN_TABELLE = "Tabelle3"
CONST AUSGABE_TABELLE = "dataPilot"
CONST AUSGABE_PILOT = "meinPilot"
'
Sub dataPilot
' objekte
oDok = ThisComponent
oAlle = oDok.Sheets()
' Blatt einfügen, wenn nicht vorhanden
If NOT oAlle.hasByName( AUSGABE_TABELLE ) Then
oAlle.insertNewByName( AUSGABE_TABELLE, oAlle.getCount() )
End If
'
oAusgabeBlatt = oAlle.getByName( AUSGABE_TABELLE )
' Datenpilot
oDPT = oAusgabeBlatt.getDataPilotTables()
If oDPT.hasByName( AUSGABE_PILOT ) Then
print "vorhanden - refresh"
' oDTP.refresh()
Else
'print "erstelle"
aOutputAddress = _
createUnoStruct( "com.sun.star.table.CellAddress" )
aOutputAddress.Sheet = oAusgabeBlatt.getRangeAddress().Sheet ' AUSGABE_TABELLE
aOutputAddress.Column = 0
aOutputAddress.Row = 0
'
aRangeAddress = _
createUnoStruct( "com.sun.star.table.CellRangeAddress" )
With aRangeAddress
.Sheet = oAlle.getByName( DATEN_TABELLE ).getRangeAddress().Sheet ' DATEN_TABELLE
.StartColumn = 0
.StartRow = 0
.EndColumn = 2
.EndRow = 17
End With
'
xDescriptor = _
oDPT.createDataPilotDescriptor()
With xDescriptor
.setName( AUSGABE_PILOT )
.setSourceRange( aRangeAddress )
End With
'
oFelder = xDescriptor.getDataPilotFields()
' Zeile
oFeld1 = oFelder.getByName( "monat" )
oFeld1.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.ROW
' Spalte
oFeld2 = oFelder.getByName( "tat" )
oFeld2.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.COLUMN
' Summe
oFeld3 = oFelder.getByName( "std" )
With oFeld3
.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.DATA
.Function = com.sun.star.sheet.GeneralFunction.SUM
End With
' Ausgabe des Piloten
oDPT.insertNewByName( AUSGABE_PILOT, aOutputAddress , xDescriptor )
End If
End Sub