[]
        
(Showing Draft Content)

ISortFields

Interface ISortFields


public interface ISortFields
Represents the sort condition list.

Provides access to the ISortField entries used by an ISort operation. Use this interface to manage the sort fields that define how data is sorted when the sort is applied.


 worksheet.getRange("A1:B4").setValue(new Object[][] {
     {"Name", "Score"},
     {"Tom", 90},
     {"Amy", 80},
     {"Tom", 70}
 });
 ITable table = worksheet.getTables().add(worksheet.getRange("A1:B4"), true);
 ISortFields sortFields = table.getSort().getSortFields();
 sortFields.add(new ValueSortField(worksheet.getRange("A2:A4"), SortOrder.Ascending));
 table.getSort().apply();
 
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(ISortField sortField)
    Adds a sort field.
    void
    Clears the sort field list.
    get(int index)
    Gets the sort field at the specified index in the sort field list.
    int
    Gets the number of sort fields in the sort field list.
    boolean
    remove(ISortField sortField)
    Removes a sort field.
  • Method Details

    • get

      ISortField get(int index)
      Gets the sort field at the specified index in the sort field list.

      Use this method to retrieve a sort field that has been added to the current ISortFields collection.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Score", "Name"},
           {2, "B"},
           {1, "C"},
           {1, "A"}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B4"), true);
       ISortFields sortFields = table.getSort().getSortFields();
       sortFields.add(new ValueSortField(worksheet.getRange("A2:A4"), SortOrder.Ascending));
       ISortField sortField = sortFields.get(0);
       
      Parameters:
      index - The index of the sort field to retrieve.
      Returns:
      The sort field at the specified index.
    • add

      void add(ISortField sortField)
      Adds a sort field.

      Use this method to add a sort condition, such as a value, icon, font color, or cell color sort field, to the sort field list returned by ISort.getSortFields(). After the required sort fields are added, call ISort.apply() to apply the sort.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Score"},
           {"Tom", 90},
           {"Amy", 75},
           {"Bob", 85}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B4"), true);
       ISortField sortField = new ValueSortField(worksheet.getRange("B1:B2"), SortOrder.Ascending);
       table.getSort().getSortFields().add(sortField);
       
      Parameters:
      sortField - The sort field to add.
    • remove

      boolean remove(ISortField sortField)
      Removes a sort field.
      
       worksheet.getRange("A1:A4").setValue(new Object[][] {{5}, {3}, {4}, {2}});
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:A4"));
       ISortField sortField = new ValueSortField(worksheet.getRange("A1:A4"));
       sort.getSortFields().add(sortField);
       boolean removed = sort.getSortFields().remove(sortField);
       
      Parameters:
      sortField - The sort field to remove.
      Returns:
      true if the specified sort field is removed; otherwise, false.
    • getCount

      int getCount()
      Gets the number of sort fields in the sort field list.

      Returns the number of sort fields in this sort field collection.

      
       worksheet.getRange("A1:A4").setValue(new Object[][] {{5}, {3}, {4}, {2}});
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:A4"));
       sort.getSortFields().add(new ValueSortField(worksheet.getRange("A1:A4")));
       int count = sort.getSortFields().getCount();
       
      Returns:
      The number of sort fields in the collection.
    • clear

      void clear()
      Clears the sort field list.

      Removes all sort fields from the sort condition list returned by ISort.getSortFields(). After this method is called, the sort no longer has any configured sort conditions until new ISortField entries are added.

      
       worksheet.getRange("A1:A4").setValue(new Object[][] {{5}, {3}, {4}, {2}});
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:A4"));
       sort.getSortFields().add(new ValueSortField(worksheet.getRange("A1:A4")));
       sort.getSortFields().clear();