[]
        
(Showing Draft Content)

ISort

Interface ISort


public interface ISort
Represents sort settings.

Provides access to sort settings for a worksheet or table, including the target range, case-sensitivity, orientation, header handling, and the list of sort fields to apply. Use setRange(IRange) to define the cells to sort, configure fields through getSortFields(), and then call apply() to perform the sort.


 worksheet.getRange("A1:B4").setValue(new Object[][] {
     {"Name", "Score"},
     {"Tom", 80},
     {"alice", 95},
     {"Bob", 90}
 });
 ISort sort = worksheet.getSort();
 sort.getSortFields().add(new ValueSortField(worksheet.getRange("A2:A4"), SortOrder.Ascending));
 sort.setRange(worksheet.getRange("A1:B4"));
 sort.setHeader(true);
 sort.setMatchCase(true);
 sort.apply();
 
  • Method Details

    • getRange

      IRange getRange()
      Gets the sort range.

      Returns the IRange that defines the cells to be sorted.

      
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:B4"));
       IRange range = sort.getRange();
       
      Returns:
      The IRange used for the sort.
    • setRange

      void setRange(IRange value)
      Sets the sort range.

      Use this method to specify the worksheet range that the current sort operation applies to before calling apply().

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Score"},
           {"Tom", 88},
           {"Amy", 92},
           {"Bob", 75}
       });
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:B4"));
       
      Parameters:
      value - The range to sort.
    • getMatchCase

      boolean getMatchCase()
      Gets whether the sort is case sensitive.

      This property indicates whether text values are compared by letter case when the sort is applied.

      
       ISort sort = worksheet.getSort();
       sort.setMatchCase(true);
       boolean matchCase = sort.getMatchCase();
       
      Returns:
      true if the sort is case sensitive; otherwise, false.
    • setMatchCase

      void setMatchCase(boolean value)
      Sets whether the sort is case sensitive.

      This property indicates whether text values are compared by letter case when the sort is applied.

      
       ISort sort = worksheet.getSort();
       sort.setMatchCase(true);
       
      Parameters:
      value - true if the sort is case sensitive; otherwise, false.
    • getOrientation

      SortOrientation getOrientation()
      Gets the sort orientation.

      The sort orientation determines whether the sort operation is applied by columns or by rows.

      
       worksheet.getSort().setRange(worksheet.getRange("A1:B4"));
       worksheet.getSort().setOrientation(SortOrientation.Columns);
       SortOrientation orientation = worksheet.getSort().getOrientation();
       
      Returns:
      The current sort orientation, such as SortOrientation.Columns or SortOrientation.Rows.
    • setOrientation

      void setOrientation(SortOrientation value)
      Sets the sort orientation.

      Use SortOrientation.Columns to sort by columns or SortOrientation.Rows to sort by rows.

      
       ISort sort = worksheet.getSort();
       sort.setOrientation(SortOrientation.Rows);
       
      Parameters:
      value - The sort orientation.
    • getSortFields

      ISortFields getSortFields()
      Gets the ISortFields object that represents the sort condition list.

      Returns the ISortFields collection that defines the sort keys for this sort operation. You can use the returned collection to add, remove, or inspect sort fields before calling apply().

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Score"},
           {"Alice", 90},
           {"Bob", 80},
           {"Carol", 95}
       });
       ISort sort = worksheet.getSort();
       sort.setRange(worksheet.getRange("A1:B4"));
       ISortFields sortFields = sort.getSortFields();
       sortFields.add(new ValueSortField(worksheet.getRange("B2:B4"), SortOrder.Descending));
       
      Returns:
      The ISortFields object that represents the sort condition list.
    • getHeader

      boolean getHeader()
      Gets whether the sort range contains a header.

      Use this property to determine whether the current sort configuration treats the first row in the sort range as a header row.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Score"},
           {"Alice", 100},
           {"Bob", 200}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B3"), true);
       boolean hasHeader = table.getSort().getHeader();
       
      Returns:
      true if the sort range contains a header row; otherwise, false.
    • setHeader

      void setHeader(boolean value)
      Sets whether the sort range contains a header.

      Use this property to set whether the current sort configuration treats the first row in the sort range as a header row.

      
       worksheet.getRange("A1:B3").setValue(new Object[][] {
           {"Name", "Score"},
           {"Alice", 100},
           {"Bob", 200}
       });
       ITable table = worksheet.getTables().add(worksheet.getRange("A1:B3"), true);
       table.getSort().setHeader(true);
       
      Parameters:
      value - true if the sort range contains a header row; otherwise, false.
    • apply

      void apply()
      Applies the configured sort settings to the current range.

      Call this method after setting the sort range and adding the required sort fields. If getHeader() returns true, the first row in the sort range is treated as a header row and is not moved.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Score"},
           {"Tom", 80},
           {"Amy", 95},
           {"Bob", 90}
       });
       ISort sort = worksheet.getSort();
       sort.getSortFields().add(new ValueSortField(worksheet.getRange("B2:B4"), SortOrder.Descending));
       sort.setRange(worksheet.getRange("A1:B4"));
       sort.setHeader(true);
       sort.apply();