Difference between revisions of "Documentation/DevGuide/Spreadsheets/Modifying a DataPilot Table"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
Line 29: Line 29:
  
  
{{Documentation/Note|Note how the field object for the third column is taken from the collection returned by <tt>getDataPilotFields()</tt> to create a second data field. If the field object was taken from the collection returned by <tt>getDataFields()</tt>, only the existing data field's function would be changed by the <tt>setPropertyValue()</tt> calls to that object.}}
+
{{Note|Note how the field object for the third column is taken from the collection returned by <tt>getDataPilotFields()</tt> to create a second data field. If the field object was taken from the collection returned by <tt>getDataFields()</tt>, only the existing data field's function would be changed by the <tt>setPropertyValue()</tt> calls to that object.}}
  
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]
 
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]]

Revision as of 20:53, 3 July 2018



The com.sun.star.sheet.DataPilotTable service is used to modify an existing DataPilot table. The object for an existing table is available through the com.sun.star.container.XNameAccess interface of the com.sun.star.sheet.DataPilotTables service. It implements the com.sun.star.sheet.XDataPilotDescriptor interface, so that the DataPilot table can be modified in the same manner as the descriptor for a new table in the preceding section. After any change to a DataPilot table's settings, the table is automatically recalculated.

Additionally, the com.sun.star.sheet.XDataPilotTable interface offers a getOutputRange() method that is used to find which range on the spreadsheet the table occupies, and a refresh() method that recalculates the table without changing any settings.

The following example modifies the table from the previous example to contain a second data field using the same source column as the existing data field, but using the "average" function instead.

 // --- Modify the DataPilot table ---
 Object aDPTableObj = xDPTables.getByName("DataPilotExample");
 xDPDesc = (com.sun.star.sheet.XDataPilotDescriptor)
     UnoRuntime.queryInterface(com.sun.star.sheet.XDataPilotDescriptor.class, aDPTableObj);
 xFields = xDPDesc.getDataPilotFields();
 
 // add a second data field from the third column, calculating the average
 aFieldObj = xFields.getByIndex(2);
 xFieldProp = (com.sun.star.beans.XPropertySet)
     UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, aFieldObj);
 xFieldProp.setPropertyValue("Orientation", com.sun.star.sheet.DataPilotFieldOrientation.DATA);
 xFieldProp.setPropertyValue("Function", com.sun.star.sheet.GeneralFunction.AVERAGE); 


Documentation note.png Note how the field object for the third column is taken from the collection returned by getDataPilotFields() to create a second data field. If the field object was taken from the collection returned by getDataFields(), only the existing data field's function would be changed by the setPropertyValue() calls to that object.
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages