locked
AutoFilter and SortState/SortCondition...sorting does not take when open the XLSX... RRS feed

  • Question

  • I have built my XLSX file in Excel.  Everything works wonderfully.

    I open my file...and I have my Filters in place.  Mind you...I am not actually filtering on anything...I just have it in place for the user to utilize.

    I do, however, want to have my 2nd column sorted.

    I set it up as follows.  No errors, etc. when I open the document.  But the 2nd column is not sorted.  I can then manually sort with no errors.

    So the goal is to have the file open up with the 2nd column already sorted.

    I made of copy of the file..opened it...manually sorted on the 2nd column...and saved.  I then used the Productivity Tool to try to find the difference.  For the life of me I cannot find it !!  I search the entire document for "sort" and there is no difference.

    What am I missing ?!?!?!

                AutoFilter autoFilter = new AutoFilter() { Reference = "A1:C1" };
                SortState sortState = new SortState() { Reference = "A2:C5000" };
                SortCondition sortCondition = new SortCondition() { Reference = "B1" };
                sortState.Append(sortCondition);
                autoFilter.Append(sortState);

    Thank you in advance for any help.

    Wednesday, December 16, 2020 9:34 PM