OO-Snippets: Datapilot

Commons

Keywords
LanguageooRexx
ApplicationCalc
AuthorsMichael Hinz (initial)
Supported Versions2.0.x  
Supported OSWin32  
QuestionHow can i add a data pilot
Answer

Code-Snippet-Listing (snippet-source)

/* get the desktop  (an Xdesktop object) */
oDesktop = UNO.createDesktop()   
xComponentLoader = oDesktop~XDesktop~XComponentLoader      --get componentLoader interface
                                                      
/* open a blank calc file */
url = "private:factory/scalc"
xCalcComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps)
/* get first  sheet in spreadsheet */
xDocument = xCalcComponent~XSpreadSheetDocument
xSheet = xDocument~getSheets~XIndexAccess~getByIndex(0)~XSpreadSheet

/* insert  values into cells */
CALL UNO.setCell xSheet, 1, 0, "Name"
CALL UNO.setCell xSheet, 2, 0, "Amount"
CALL UNO.setCell xSheet, 3, 0, "Month"
CALL UNO.setCell xSheet, 1, 1, "Michael"
CALL UNO.setCell xSheet, 1, 2, "John"
CALL UNO.setCell xSheet, 1, 3, "John"
CALL UNO.setCell xSheet, 1, 4, "Michael"
CALL UNO.setCell xSheet, 1, 5, "Michael"
CALL UNO.setCell xSheet, 1, 6, "John"
CALL UNO.setCell xSheet, 1, 7, "John"
CALL UNO.setCell xSheet, 1, 8, "Michael"
CALL UNO.setCell xSheet, 2, 1, 100
CALL UNO.setCell xSheet, 2, 2, 200
CALL UNO.setCell xSheet, 2, 3, 123
CALL UNO.setCell xSheet, 2, 4, 12
CALL UNO.setCell xSheet, 2, 5, 100
CALL UNO.setCell xSheet, 2, 6, 200
CALL UNO.setCell xSheet, 2, 7, 123
CALL UNO.setCell xSheet, 2, 8, 12
CALL UNO.setCell xSheet, 3, 4, 2
CALL UNO.setCell xSheet, 3, 1, 2
CALL UNO.setCell xSheet, 3, 2, 1
CALL UNO.setCell xSheet, 3, 3, 1
CALL UNO.setCell xSheet, 3, 5, 2
CALL UNO.setCell xSheet, 3, 6, 2
CALL UNO.setCell xSheet, 3, 7, 1
CALL UNO.setCell xSheet, 3, 8, 1

/*get  cell range*/
xCellRange = xSheet~xCellRange~getCellRangeByName("A1:D9")
xCellRangeAddress = xCellRange~XCellRangeAddressable~getRangeAddress

/*create createDataPilotDescriptor by calling  XDataPilotTablesSupplie*/
xDataSupplier = xSheet~XDataPilotTablesSupplier
xData = xDataSupplier~getDataPilotTables()
xDataDescript = xData~createDataPilotDescriptor()

xDataDescript~setSourceRange(xCellRangeAddress)

myRange = xSheet~getCellByPosition(1, 10)
myAddr = myRange~XCellAddressable~getCellAddress

xFields = xDataDescript~getDataPilotFields()     -- get  DataPilotFields

/*apply values to DataPilotFields*/
aFieldObj = xFields~getByIndex(1)
aFieldObj~xPropertySet~setPropertyValue("Orientation",bsf.getConstant("com.sun.star.sheet.DataPilotFieldOrientation","COLUMN"))
aFieldObj = xFields~getByIndex(3)
aFieldObj~xPropertySet~setPropertyValue("Orientation",bsf.getConstant("com.sun.star.sheet.DataPilotFieldOrientation","ROW"))
aFieldObj = xFields~getByIndex(2)
aFieldObj~xPropertySet~setPropertyValue("Orientation", bsf.getConstant("com.sun.star.sheet.DataPilotFieldOrientation","DATA"))

aFieldObj~xPropertySet~setPropertyValue("Function", bsf.getConstant("com.sun.star.sheet.GeneralFunction", "SUM"))

/*apply data pilot  to sheet*/
xData~insertNewByName("DataPilotExample", myAddr, xDataDescript)

::requires UNO.CLS   -- get UNO support

Changelog

DateUserModification

and