[]
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();
voidapply()booleanbooleangetRange()ISortFields object that represents the sort condition list.voidsetHeader(boolean value) voidsetMatchCase(boolean value) voidsetOrientation(SortOrientation value) voidReturns the IRange that defines the cells to be sorted.
ISort sort = worksheet.getSort();
sort.setRange(worksheet.getRange("A1:B4"));
IRange range = sort.getRange();
IRange used for the sort.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"));
value - The range to sort.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();
true if the sort is case sensitive; otherwise, false.This property indicates whether text values are compared by letter case when the sort is applied.
ISort sort = worksheet.getSort();
sort.setMatchCase(true);
value - true if the sort is case sensitive; otherwise, false.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();
SortOrientation.Columns or SortOrientation.Rows.Use SortOrientation.Columns to sort by columns or SortOrientation.Rows to sort by rows.
ISort sort = worksheet.getSort();
sort.setOrientation(SortOrientation.Rows);
value - The sort orientation.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));
ISortFields object that represents the sort condition list.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();
true if the sort range contains a header row; otherwise, false.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);
value - true if the sort range contains a header row; otherwise, false.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();