Michael Hinz
How can i add a data pilot
/* get the desktop (an Xdesktop object) */
oDesktop = UNO.createDesktop()
xComponentLoader = oDesktop~{%see com.sun.star.frame.XDesktop%XDesktop}~{%see com.sun.star.frame.XComponentLoader%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~{%see com.sun.star.sheet.XSpreadsheetDocument%XSpreadSheetDocument}
xSheet = xDocument~getSheets~{%see com.sun.star.container.XIndexAccess%XIndexAccess}~getByIndex(0)~{%see com.sun.star.sheet.XSpreadsheet%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~{%see com.sun.star.table.XCellRange%xCellRange}~getCellRangeByName("A1:D9")
xCellRangeAddress = xCellRange~{%see com.sun.star.sheet.XCellRangeAddressable%XCellRangeAddressable}~getRangeAddress
/*create createDataPilotDescriptor by calling XDataPilotTablesSupplie*/
xDataSupplier = xSheet~{%see com.sun.star.sheet.XDataPilotTablesSupplier%XDataPilotTablesSupplier}
xData = xDataSupplier~getDataPilotTables()
xDataDescript = xData~createDataPilotDescriptor()
xDataDescript~setSourceRange(xCellRangeAddress)
myRange = xSheet~getCellByPosition(1, 10)
myAddr = myRange~{%see com.sun.star.sheet.XCellAddressable%XCellAddressable}~getCellAddress
xFields = xDataDescript~getDataPilotFields() -- get DataPilotFields
/*apply values to DataPilotFields*/
aFieldObj = xFields~getByIndex(1)
aFieldObj~{%see com.sun.star.beans.XPropertySet%xPropertySet}~setPropertyValue("Orientation",bsf.getConstant("{%see com.sun.star.sheet.DataPilotFieldOrientation}","COLUMN"))
aFieldObj = xFields~getByIndex(3)
aFieldObj~{%see com.sun.star.beans.XPropertySet%xPropertySet}~setPropertyValue("Orientation",bsf.getConstant("{%see com.sun.star.sheet.DataPilotFieldOrientation}","ROW"))
aFieldObj = xFields~getByIndex(2)
aFieldObj~{%see com.sun.star.beans.XPropertySet%xPropertySet}~setPropertyValue("Orientation", bsf.getConstant("{%see com.sun.star.sheet.DataPilotFieldOrientation}","DATA"))
aFieldObj~{%see com.sun.star.beans.XPropertySet%xPropertySet}~setPropertyValue("Function", bsf.getConstant("{%see com.sun.star.sheet.GeneralFunction}", "SUM"))
/*apply data pilot to sheet*/
xData~insertNewByName("DataPilotExample", myAddr, xDataDescript)
::requires UNO.CLS -- get UNO support