-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Sorting by 1 or more Columns #78
Comments
There's an implementation in version 4.5 beta, so try it out and see if it works for you. |
thanks forthe quick response I got the reference for sort. I started using it but wonder how to use it for more than 1 columns like below: Is it possible to implement this interop code to epplus? Thanks JanKallman |
The syntax for more than one column is like this... /// <summary>
/// Sort the range by value
/// </summary>
/// <param name="columns">The column(s) to sort by within the range. Zerobased</param>
/// <param name="descending">Descending if true, otherwise Ascending. Default Ascending. Zerobased</param>
/// <param name="culture">The CultureInfo used to compare values. A null value means CurrentCulture</param>
/// <param name="compareOptions">String compare option</param>
public void Sort(int[] columns, bool[] descending=null, CultureInfo culture=null, CompareOptions compareOptions=CompareOptions.None) So, //Sort column B, descending then A ascending
ws.Cells["A:C"].Sort(new int[] { 1,0 }, new bool[] { true,false });
//Sort column A only, descending
ws.Cells["A:C"].Sort(0, true);
//Sort column B, Ascending
ws.Cells["A:C"].Sort(1);
//Sort column A, ascending
ws.Cells["A:C"].Sort(); Let me know if you have any problems |
Added to 4.5.1 |
not same order if I do manually in Excel (order by a Column Index, Expand the selection) and sort it using code (Sort). |
Any chance to add support for custom sort order? Excel supports a custom sort list, which controls the order of the field being sorted. My particular use case is to sort on Employee ID as column 1, then Relationship as column 2 with the order {"Employee", "Spouse", "Child"}. I can easily do the sort in my program logic before populating the worksheet, so I have an easy workaround. |
The order I am getting from using sort is different then the order I get while sorting manually on a worksheet. Select cells to sort > Sort > Sort by column x. Is there any solution to this issue? @kiquenet did you ever solve this issue? |
I see this has not been updated since couple of years here : https://epplus.codeplex.com/workitem/14791
Wish to know any plans for implementing Sorting since for files already having data with some formatting its difficult, I want to sort few data based on 3 columns please guide?
Also the present Sort in place in EPPLUS does not work for me. when I try adding r.Sort(...) ;
Error
CS1061 'ExcelRange' does not contain a definition for 'Sort' and no extension method 'Sort' accepting a first argument of type 'ExcelRange' could be found (are you missing a using directive or an assembly reference?)
The text was updated successfully, but these errors were encountered: