DsExcel .NET provides an option to apply sorting on a specific table in the worksheet. To accomplish this, you can use the Sort property of the ITable interface. The Apply method is used to apply the selected sort state and display the results.
Refer to the following example code to apply table sorting in a worksheet.
C# |
Copy Code |
---|---|
// Assigning Value to the range worksheet.Range["A2"].Value = 3; worksheet.Range["A3"].Value = 4; worksheet.Range["A4"].Value = 2; worksheet.Range["A5"].Value = 1; worksheet.Range["B2"].Value = 1; worksheet.Range["B3"].Value = 2; worksheet.Range["B4"].Value = 3; worksheet.Range["B5"].Value = 4; worksheet.Range["F2"].Value = "aaa"; worksheet.Range["F3"].Value = "bbb"; worksheet.Range["F4"].Value = "ccc"; worksheet.Range["F5"].Value = "ddd"; worksheet.Range["B2:B5"].FormatConditions.AddIconSetCondition(); //Sort by column A firstly, then by column B. ValueSortField key1 = new ValueSortField(worksheet.Range["A1:A2"], SortOrder.Ascending); IconSortField key2 = new IconSortField(worksheet.Range["B1:B2"], workbook.IconSets[IconSetType.Icon3Arrows][1], SortOrder.Descending); table.Sort.SortFields.Add(key1); table.Sort.SortFields.Add(key2); table.Sort.Apply(); |