diff --git a/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/README.md b/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/README.md index a39cff78..720ac044 100644 --- a/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/README.md +++ b/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/README.md @@ -29,11 +29,14 @@ using (ExcelEngine excelEngine = new ExcelEngine()) IDataSort sorter = workbook.CreateDataSorter(); //Range to sort - sorter.SortRange = worksheet.Range["A1:A11"]; + sorter.SortRange = worksheet.Range["A1:B11"]; - //Adds the sort field with the column index, sort based on and order by attribute + //Adds a sort field: sort by values in column A in ascending order sorter.SortFields.Add(0, SortOn.Values, OrderBy.Ascending); + //Adds a sort field: then by values in column B in descending order + sorter.SortFields.Add(1, SortOn.Values, OrderBy.Descending); + //Sort based on the sort Field attribute sorter.Sort(); @@ -41,10 +44,10 @@ using (ExcelEngine excelEngine = new ExcelEngine()) sorter = workbook.CreateDataSorter(); //Range to sort - sorter.SortRange = worksheet.Range["B1:B11"]; + sorter.SortRange = worksheet.Range["C1:C11"]; - //Adds the sort field with the column index, sort based on and order by attribute - sorter.SortFields.Add(1, SortOn.Values, OrderBy.Descending); + //Adds a sort field: sort by values in column C in descending order + sorter.SortFields.Add(2, SortOn.Values, OrderBy.Descending); //Sort based on the sort Field attribute sorter.Sort(); diff --git a/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values/Data/InputTemplate.xlsx b/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values/Data/InputTemplate.xlsx index 2a78a7c5..5341b0fc 100644 Binary files a/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values/Data/InputTemplate.xlsx and b/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values/Data/InputTemplate.xlsx differ diff --git a/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values/Program.cs b/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values/Program.cs index 77d76ff9..aacd6d4b 100644 --- a/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values/Program.cs +++ b/Editing Excel cells/Sort On Cell Values/.NET/Sort On Cell Values/Sort On Cell Values/Program.cs @@ -20,11 +20,14 @@ static void Main(string[] args) IDataSort sorter = workbook.CreateDataSorter(); //Range to sort - sorter.SortRange = worksheet.Range["A1:A11"]; + sorter.SortRange = worksheet.Range["A1:B11"]; - //Adds the sort field with the column index, sort based on and order by attribute + //Adds a sort field: sort by values in column A in ascending order sorter.SortFields.Add(0, SortOn.Values, OrderBy.Ascending); + //Adds a sort field: then by values in column B in descending order + sorter.SortFields.Add(1, SortOn.Values, OrderBy.Descending); + //Sort based on the sort Field attribute sorter.Sort(); @@ -32,10 +35,10 @@ static void Main(string[] args) sorter = workbook.CreateDataSorter(); //Range to sort - sorter.SortRange = worksheet.Range["B1:B11"]; + sorter.SortRange = worksheet.Range["C1:C11"]; - //Adds the sort field with the column index, sort based on and order by attribute - sorter.SortFields.Add(1, SortOn.Values, OrderBy.Descending); + //Adds a sort field: sort by values in column C in descending order + sorter.SortFields.Add(2, SortOn.Values, OrderBy.Descending); //Sort based on the sort Field attribute sorter.Sort();