I have been producing excel files with open XML and I know how to set up the sort criteria. What I don't understand is how to invoke the actual sort. Any help will be appreciated.
I have been producing excel files with open XML and I know how to set up the sort criteria. What I don't understand is how to invoke the actual sort. Any help will be appreciated.
@JimWilson-3906,
Welcome to Q&A forum!
Since the tag office-excel-itpro focuses on general issues about Excel client, I will remove it.
And maybe you could add openspecs-office-fileformats tag for more reated help.
Thanks for your understanding!
Could you please show some of your current code and let us move on based on your code?
I used ClosedXml to write some code, this library is a layer of encapsulation of OpenXML API, see if this is suitable for you.
static void Main(string[] args)
{
DataTable dataTable = GetDataTable();
ExportData();
}
static DataTable GetDataTable()
{
DataTable dataTable = new DataTable();
dataTable.Columns.Add("ID", typeof(int));
dataTable.Columns.Add("Name", typeof(string));
dataTable.Columns.Add("Math", typeof(double));
dataTable.Columns.Add("Science", typeof(double));
dataTable.Columns.Add("History", typeof(double));
dataTable.Rows.Add(1, "Timon", 75.2, 98, 74);
dataTable.Rows.Add(2, "Tom", 85, 83, 54);
dataTable.Rows.Add(3, "Jerry", 35.4, 77, 25);
return dataTable;
}
private static void ExportData()
{
var wb = new XLWorkbook();
DataTable dt = GetDataTable();
var wsTable = wb.Worksheets.Add(dt,"Table");
var rangeTable = wsTable.RangeUsed();
var table = rangeTable.CopyTo(wsTable.Column(wsTable.LastColumnUsed().ColumnNumber() + 3)).CreateTable();
table.Sort("History Asc");
wb.SaveAs(@"C:\xxx\SortExamples1.xlsx");
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
9 people are following this question.
Insert a node as child ,before or after a node in nested dynamic JSON Node using C#
Visual Studio 2019: Undefined behavior in a C++/CLI wrapper project.
Example for how to get Package Metadata from Azure DevOps Rest-Api Artifacts using c#
How to collapse individual nested grids/stackpanels inside a grid?