SetSort

function SetSort(
  key1: ApiRange | String = null,
  sSortOrder1: SortOrder = null,
  key2: ApiRange | String = null,
  sSortOrder2: SortOrder = null,
  key3: ApiRange | String = null,
  sSortOrder3: SortOrder = null,
  sHeader: SortHeader = null,
  sOrientation: SortOrientation = null,
): void

Description

Sorts the cells in the given range by the parameters specified in the request.

Parameters

key1ApiRange | Stringdefault: null

First sort field.

sSortOrder1SortOrderdefault: null

The sort order for the values specified in Key1.

key2ApiRange | Stringdefault: null

Second sort field.

sSortOrder2SortOrderdefault: null

The sort order for the values specified in Key2.

key3ApiRange | Stringdefault: null

Third sort field.

sSortOrder3SortOrderdefault: null

The sort order for the values specified in Key3.

sHeaderSortHeaderdefault: null

Specifies whether the first row contains header information.

sOrientationSortOrientationdefault: null

Specifies if the sort should be by row (default) or column.

Returns

void

Try It

var oWorksheet = Api.GetActiveSheet();
oWorksheet.GetRange("A1").SetValue(2016);
oWorksheet.GetRange("A2").SetValue(2015);
oWorksheet.GetRange("A3").SetValue(2018);
oWorksheet.GetRange("A4").SetValue(2014);
oWorksheet.GetRange("A5").SetValue(2010);
oWorksheet.GetRange("B1").SetValue(150);
oWorksheet.GetRange("B2").SetValue(200);
oWorksheet.GetRange("B3").SetValue(260);
oWorksheet.GetRange("B4").SetValue(120);
oWorksheet.GetRange("B5").SetValue(100);
oWorksheet.GetRange("C1").SetValue("C");
oWorksheet.GetRange("C2").SetValue("B");
oWorksheet.GetRange("C3").SetValue("A");
oWorksheet.GetRange("C4").SetValue("G");
oWorksheet.GetRange("C5").SetValue("E");
oWorksheet.GetRange("A1:C5").SetSort("A1:A5", "xlAscending", "B1:B5", "xlDescending", "C1:C5", "xlAscending", "xlYes", "xlSortColumns");

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).