An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
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.