跳到主要内容

Add2

添加支持链接数据类型(股票、地理)子字段的排序字段。

备注

此功能仅在 ONLYOFFICE Docs 付费版本中可用。

语法

expression.Add2(Key, SortOn, Order, CustomOrder, DataOption, SubField);

expression - 表示 ApiSortFields 类的变量。

参数

名称必需/可选数据类型默认值描述
Key必需ApiRange表格内定义排序列的范围。
SortOn可选XlSortOn"xlSortOnValues"用作排序条件的值。
Order可选SortOrder"xlAscending"排序顺序。
CustomOrder可选number | string0保留。引擎尚不支持自定义顺序排序。
DataOption可选XlSortDataOption"xlSortNormal"数据排序选项。
SubField可选string链接数据类型的子字段名称(例如 “Population”、“Volume”)。

返回值

ApiSortField | null

示例

注册一个排序列,该列还可以针对电子表格中链接数据类型的子属性。

// How do I add a sort column with an optional sub-property for linked data in a spreadsheet?

// Supply a subfield alongside the column to refine what value the sort reads from each cell in a spreadsheet.

let worksheet = Api.GetActiveSheet();
worksheet.GetRange("A1").SetValue("Product");
worksheet.GetRange("A2").SetValue("Oranges");
worksheet.GetRange("A3").SetValue("Apples");
worksheet.GetRange("A4").SetValue("Bananas");
let table = worksheet.AddListObject("xlSrcRange", "A1:A4");

let sort = table.GetSort();
let sortFields = sort.GetSortFields();
sortFields.Add2(worksheet.GetRange("A1"), "xlSortOnValues", "xlAscending", null, "xlSortNormal", null);

worksheet.GetRange("C1").SetValue("Fields count:");
worksheet.GetRange("D1").SetValue(sortFields.GetCount());
worksheet.GetRange("C2").SetValue("First product after sort:");
worksheet.GetRange("D2").SetValue(worksheet.GetRange("A2").GetValue());