I wanted to sort my output using the autofilter in excel. I could not find the way to do so in the example files, so I took a look at the XML code of an excel file I saved after applying the sort method to it.
I noticed this in the XML:
so I added it to C# the code like this:
var filterDef = new XElement("sortState");
filterDef.Add(new XAttribute("ref", "A3:L597"));
filterDef.Add(new XElement("sortCondition", new XAttribute("ref", "E2")));
autoFilterNode.InnerXml += filterDef.ToString();
build the excel file, using the C# code. When I opened the excel file, the sort seems to be applied when you see the autofilter drop down in the specific column. But the sorting was actually not done.
I checked the XML code of the code-written excel sheet and the autoFilter element attributes and sub elements are exactly the same.
Generated XML code via C#
<sortCondition ref="E2" />
I also did a ws.Calculate() and _package.Workbook.Calculate() prior to saving the file.
What do I need to do to get the sorting right?