From Apache OpenOffice Wiki
Jump to: navigation, search

A object is created using the createSubTotalDescriptor() method from the range's interface to create subtotals for a cell range. After applying the settings to the descriptor, it is passed to the applySubTotals() method.

The bEmpty parameter to the createSubTotalDescriptor() method works in the same manner as the parameter to the createFilterDescriptor() method described in the filtering section. If the bReplace parameter to the applySubTotals() method is true, existing subtotal rows are deleted before inserting new ones.

The removeSubTotals() method removes the subtotal rows from the cell range without modifying the stored subtotal settings, so that the same subtotals can later be restored.


New fields are added to the subtotal descriptor using the interface's addNew() method. The nGroupColumn parameter selects the column by which values are grouped. The subtotals are inserted at changes of the column's values. The aSubTotalColumns parameter specifies which column subtotal values are calculated. It is a sequence of entries where each entry contains the column number and the function to be calculated.

To query or modify the fields in a subtotal descriptor, the interface is used to access the fields. Each field's interface gets and sets the group and subtotal columns.

The example below creates subtotals, grouping by the first column and calculating the sum of the third column:

  // --- insert subtotals --- xSub = (
      UnoRuntime.queryInterface(, xRange); xSubDesc = xSub.createSubTotalDescriptor(true);[] aColumns = new[1];
  // calculate sum of third column
  aColumns[0] = new;
  aColumns[0].Column = 2;
  aColumns[0].Function =;
  // group by first column
  xSubDesc.addNew(aColumns, 0);
  xSub.applySubTotals(xSubDesc, true);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages