File tree Expand file tree Collapse file tree 3 files changed +16
-10
lines changed
Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values Expand file tree Collapse file tree 3 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -29,22 +29,25 @@ using (ExcelEngine excelEngine = new ExcelEngine())
2929 IDataSort sorter = workbook.CreateDataSorter();
3030
3131 //Range to sort
32- sorter.SortRange = worksheet.Range["A1:A11"] ;
32+ sorter.SortRange = worksheet.UsedRange ;
3333
34- //Adds the sort field with the column index, sort based on and order by attribute
34+ //Adds a sort field: sort by values in column A in ascending order
3535 sorter.SortFields.Add(0, SortOn.Values, OrderBy.Ascending);
3636
37+ //Adds a sort field: then by values in column B in descending order
38+ sorter.SortFields.Add(1, SortOn.Values, OrderBy.Descending);
39+
3740 //Sort based on the sort Field attribute
3841 sorter.Sort();
3942
4043 //Creates the data sorter
4144 sorter = workbook.CreateDataSorter();
4245
4346 //Range to sort
44- sorter.SortRange = worksheet.Range["B1:B11"] ;
47+ sorter.SortRange = worksheet.UsedRange ;
4548
46- //Adds the sort field with the column index, sort based on and order by attribute
47- sorter.SortFields.Add(1 , SortOn.Values, OrderBy.Descending);
49+ //Adds a sort field: sort by values in column C in descending order
50+ sorter.SortFields.Add(2 , SortOn.Values, OrderBy.Descending);
4851
4952 //Sort based on the sort Field attribute
5053 sorter.Sort();
Original file line number Diff line number Diff line change @@ -20,22 +20,25 @@ static void Main(string[] args)
2020 IDataSort sorter = workbook . CreateDataSorter ( ) ;
2121
2222 //Range to sort
23- sorter . SortRange = worksheet . Range [ "A1:A11" ] ;
23+ sorter . SortRange = worksheet . UsedRange ;
2424
25- //Adds the sort field with the column index, sort based on and order by attribute
25+ //Adds a sort field: sort by values in column A in ascending order
2626 sorter . SortFields . Add ( 0 , SortOn . Values , OrderBy . Ascending ) ;
2727
28+ //Adds a sort field: then by values in column B in descending order
29+ sorter . SortFields . Add ( 1 , SortOn . Values , OrderBy . Descending ) ;
30+
2831 //Sort based on the sort Field attribute
2932 sorter . Sort ( ) ;
3033
3134 //Creates the data sorter
3235 sorter = workbook . CreateDataSorter ( ) ;
3336
3437 //Range to sort
35- sorter . SortRange = worksheet . Range [ "B1:B11" ] ;
38+ sorter . SortRange = worksheet . UsedRange ;
3639
37- //Adds the sort field with the column index, sort based on and order by attribute
38- sorter . SortFields . Add ( 1 , SortOn . Values , OrderBy . Descending ) ;
40+ //Adds a sort field: sort by values in column C in descending order
41+ sorter . SortFields . Add ( 2 , SortOn . Values , OrderBy . Descending ) ;
3942
4043 //Sort based on the sort Field attribute
4144 sorter . Sort ( ) ;
You can’t perform that action at this time.
0 commit comments