[]
        
(Showing Draft Content)

IconSortField

Class IconSortField

java.lang.Object
com.grapecity.documents.excel.SortFieldBase
com.grapecity.documents.excel.IconSortField
All Implemented Interfaces:
IIconSortField, ISortField

public class IconSortField extends SortFieldBase implements IIconSortField
Represents a sort field that sorts data by a specified conditional-formatting icon.

Use this class to add an icon-based sort condition to a worksheet or table sort. The sort key identifies the cells whose displayed icons are evaluated, and the target IIcon specifies which icon is sorted according to the given SortOrder.


 worksheet.getRange("A1:B4").setValue(new Object[][] {
     {"Name", "Score"},
     {"A", 90},
     {"B", 70},
     {"C", 50}
 });
 IIconSetCondition iconSet = worksheet.getRange("B2:B4").getFormatConditions().addIconSetCondition();
 iconSet.setIconSet(workbook.getIconSets().get(IconSetType.Icon3TrafficLights1));
 IconSortField sortField = new IconSortField(
     worksheet.getRange("B2:B4"),
     workbook.getIconSets().get(IconSetType.Icon3TrafficLights1).get(2),
     SortOrder.Ascending);
 worksheet.getSort().getSortFields().add(sortField);
 
  • Constructor Details

    • IconSortField

      public IconSortField(IRange key, IIcon icon)
      Sorts by icon.

      This constructor forwards to IconSortField(IRange,IIcon,SortOrder) with SortOrder.Ascending.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"A", 2}, {"B", 1}, {"C", 1}, {"D", 3}
       });
       IIconSetCondition iconSet = worksheet.getRange("B1:B4").getFormatConditions().addIconSetCondition();
       iconSet.setIconSet(workbook.getIconSets().get(IconSetType.Icon3TrafficLights1));
       IconSortField sortField = new IconSortField(
           worksheet.getRange("B1:B4"),
           workbook.getIconSets().get(IconSetType.Icon3TrafficLights1).get(0));
       worksheet.getSort().getSortFields().add(sortField);
       
      Parameters:
      key - The range used as the sort key.
      icon - The icon to sort by. Must not be null.
    • IconSortField

      public IconSortField(IRange key, IIcon icon, SortOrder order)
      Creates a sort field that sorts a range by a specified conditional-formatting icon.

      Use this constructor to define an icon-based sort criterion for the specified sort key range. The key identifies the cells whose displayed icons are evaluated, icon specifies the icon to sort by, and order determines whether matching icons are sorted in ascending or descending order.

      
       worksheet.getRange("A1:B4").setValue(new Object[][] {
           {"Name", "Score"},
           {"A", 90},
           {"B", 70},
           {"C", 50}
       });
       IIconSetCondition iconSet = worksheet.getRange("B2:B4").getFormatConditions().addIconSetCondition();
       iconSet.setIconSet(workbook.getIconSets().get(IconSetType.Icon3TrafficLights1));
       IconSortField sortField = new IconSortField(
           worksheet.getRange("B2:B4"),
           workbook.getIconSets().get(IconSetType.Icon3TrafficLights1).get(2),
           SortOrder.Ascending);
       
      Parameters:
      key - The range used as the sort key. Its displayed conditional-formatting icons are used for sorting.
      icon - The icon used as the sort criterion.
      order - The sort order to apply to the icon-based sort field.
  • Method Details

    • getOrder

      public final SortOrder getOrder()
      Gets the sort order.

      Returns the SortOrder that determines whether matching icons are sorted in ascending or descending order.

      
       worksheet.getRange("A1:A4").setValue(new Object[] {3, 1, 4, 2});
       IIcon icon = workbook.getIconSets().get(IconSetType.Icon3TrafficLights1).get(0);
       IconSortField sortField = new IconSortField(worksheet.getRange("A1:A4"), icon, SortOrder.Descending);
       SortOrder order = sortField.getOrder();
       
      Specified by:
      getOrder in interface IIconSortField
      Returns:
      The sort order for this icon sort field.
    • getIcon

      public final IIcon getIcon()
      Gets the IIcon object used to sort by.

      Use this method to retrieve the icon criterion associated with the current icon sort field.

      
       IIcon icon = workbook.getIconSets().get(IconSetType.Icon3Arrows).get(0);
       IconSortField sortField = new IconSortField(worksheet.getRange("A2:A4"), icon);
       IIcon sortIcon = sortField.getIcon();
       
      Specified by:
      getIcon in interface IIconSortField
      Returns:
      The IIcon object used to sort by.