Difference between revisions of "Data pilots"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
m
 
(4 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
=Current data pilot=
 
=Current data pilot=
<code>[oobas]
+
<syntaxhighlight lang="oobas">
 
Function fnCurDataPilot(oCursor as object) as object
 
Function fnCurDataPilot(oCursor as object) as object
 
   
 
   
Line 20: Line 20:
 
'fnCurDataPilot = null
 
'fnCurDataPilot = null
 
end function
 
end function
</code>
+
</syntaxhighlight>
 
Example of calling the above function:  
 
Example of calling the above function:  
  
<code>[oobas]
+
<syntaxhighlight lang="oobas">
 
oDoc = thisComponent
 
oDoc = thisComponent
 
oCurSelection = oDoc.CurrentSelection
 
oCurSelection = oDoc.CurrentSelection
Line 29: Line 29:
 
oCursor = oSheet.createCursorbyRange(oCurSelection)
 
oCursor = oSheet.createCursorbyRange(oCurSelection)
 
oDataPilot = fnCurDataPilot(oCursor)
 
oDataPilot = fnCurDataPilot(oCursor)
</code>
+
</syntaxhighlight>
  
 
=Delete datapilot=
 
=Delete datapilot=
<code>[oobas]
+
<syntaxhighlight lang="oobas">
 
sub subDeleteDataPilot(oDoc, oDataPilot)
 
sub subDeleteDataPilot(oDoc, oDataPilot)
 
oDoc.getsheets.getByIndex(oDataPilot.getOutputRange.sheet).getDataPilotTables.removeByName(oDataPilot.Name)
 
oDoc.getsheets.getByIndex(oDataPilot.getOutputRange.sheet).getDataPilotTables.removeByName(oDataPilot.Name)
 
end sub
 
end sub
</code>
+
</syntaxhighlight>
 +
 
 +
[[Category:Basic:Tutorials]]
 +
[[Category:Calc]]
 +
[[Category:API]]

Latest revision as of 12:45, 4 February 2021

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