Data pilots

From Apache OpenOffice Wiki
Revision as of 12:45, 4 February 2021 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The last I looked it was not possible to access a DataPilot based on external data via the API - so these routines are for DataPilots based on data within the spreadsheet.

Current data pilot

Function fnCurDataPilot(oCursor as object) as object
 
'Returns the first data pilot that intersects with oCursor
'If no data pilot intersects it returns null
 
dim oEnum as object,  oDP as object
 
oEnum = thisComponent.getCurrentController.getActiveSheet.getDataPilotTables.createEnumeration
While oEnum.hasMoreElements()
        oDP = oEnum.nextElement()
        if oCursor.queryIntersection(oDP.outputRange).getCount > 0 then
                fnCurDataPilot = oDp
                exit function
        end if
wend
'fnCurDataPilot = null
end function

Example of calling the above function:

oDoc = thisComponent
oCurSelection = oDoc.CurrentSelection
oSheet = oDoc.CurrentController.ActiveSheet
oCursor = oSheet.createCursorbyRange(oCurSelection)
oDataPilot = fnCurDataPilot(oCursor)

Delete datapilot

sub subDeleteDataPilot(oDoc, oDataPilot)
oDoc.getsheets.getByIndex(oDataPilot.getOutputRange.sheet).getDataPilotTables.removeByName(oDataPilot.Name)
end sub
Personal tools