From Apache OpenOffice Wiki
Jump to: navigation, search

Table Sort Descriptor

A sort descriptor describes all properties of a sort operation. The service extends the service with table specific sorting properties, such as:

The sorting orientation using the boolean IsSortColumns.

A sequence of sorting fields using the SortFields property that contains a sequence of structs.

The size of the sequence using the MaxSortFieldsCount property.

The service extends the service spreadsheet specific sorting properties, such as:

Moving cell formats with the cells they belong to using the boolean property BindFormatsToContent.The existence of column or row headers using the boolean property ContainsHeader.

Copying the sorted data to another position in the document using the boolean property CopyOutputData.

Position where sorted data are to be copied using the property OutputPosition.

If the IsUserListEnabled property is true, a user-defined sort list is used that specifies an order for the strings it contains. The UserListIndex property selects an entry from the UserLists property of the service to find the sort list that is used.


To sort the contents of a cell range, the sort() method from the interface is called, passing a sequence of property values with properties from the service. The sequence can be constructed from scratch containing the properties that should be set, or the return value of the createSortDescriptor() method can be used and modified. If the cell range is a database range that has a stored sort operation, createSortDescriptor() returns a sequence with the options of this sort operation.

The fields that the cell range is sorted by are specified in the SortFields property as a sequence of elements. In the struct, the Field member specifies the field number by which to sort, and the boolean IsAscending member switches between ascending and descending sorting for that field. The boolean IsCaseSensitive specifies whether the case of letters is important when comparing entries. The CollatorLocale is used to sort according to the sorting rules of a given locale. For some locales, several different sorting rules exist. In this case, the CollatorAlgorithm is used to select one of the sorting rules. The service is used to find the possible CollatorAlgorithm values for a locale. Currently, it is not possible to have different locales, algorithms and case sensitivity on the different fields.

Documentation note.png The FieldType member, that is used to select textual or numeric sorting in text documents is ignored in the spreadsheet application. In a spreadsheet, a cell always has a known type of text or value, which is used for sorting, with numbers sorted before text cells.

The following example sorts the cell range by the second column in ascending order:

  // --- sort by second column, ascending ---
  // define the fields to sort[] aSortFields = new[1];
  aSortFields[0] = new;
  aSortFields[0].Field = 1;
  aSortFields[0].IsAscending = true;
  aSortFields[0].IsCaseSensitive = false;
  // define the sort descriptor[] aSortDesc = new[2];
  aSortDesc[0] = new;
  aSortDesc[0].Name = "SortFields";
  aSortDesc[0].Value = aSortFields;
  aSortDesc[1] = new;
  aSortDesc[1].Name = "ContainsHeader";
  aSortDesc[1].Value = new Boolean(true);
  // perform the sorting xSort = (
      UnoRuntime.queryInterface(, xRange);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages