Custom sort using ValueSortField

Posted by: srg13 on 10 June 2023, 8:04 am EST

    • Post Options:
    • Link

    Posted 10 June 2023, 8:04 am EST

    Hi,

    I have to sort my excel data based on a date field. I tried the below code from demo but somehow I am not able to change it for date sorting. Can you please help share an example of using valuesortfield for sorting the excel on date column?

    My date column has number format :- d-mmm-yy

    Thanks

    var sortkey = new ValueSortField(worksheet.Range[“A1:A2”], “1,2,3”);

    worksheet.Range[“A2:A6”].Sort(SortOrientation.Columns, false, sortkey);

  • Posted 10 June 2023, 10:33 am EST

    Just to add some more details. I am getting the data as string from the upstream system and i am using the below code to parse it to date

    if (DateTime.TryParse(cellValue, out dt) == true)

    range.Value = dt.ToString(“d-mmm-yy”, CultureInfo.InvariantCulture);

    Sorting needs to be performed later on this date column

  • Posted 12 June 2023, 5:07 am EST

    There was an issue with the data coming from backend.

    var sortkey = new ValueSortField(worksheet.Range[“A1:A2”], “1,2,3”); worked after correcting the data…

    Thanks

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels