From 376ca365a3ffab5fa0a6039f0824a3751c3fead6 Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Mon, 13 Apr 2026 23:13:26 +0530 Subject: [PATCH 1/2] 1008504 - Content added --- Document-Processing-toc.html | 3 + ...to-sort-a-column-by-including-first-row.md | 113 ++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-sort-a-column-by-including-first-row.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 16dbff91c..d435b1c1b 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6612,6 +6612,9 @@
  • How to retrieve the name of the chart in an Excel worksheet?
  • +
  • + How to sort a column by including first row? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-sort-a-column-by-including-first-row.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-sort-a-column-by-including-first-row.md new file mode 100644 index 000000000..07bd5c5fb --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-sort-a-column-by-including-first-row.md @@ -0,0 +1,113 @@ +--- +title: Soritng using Syncfusion XLsIO | Syncfusion +description: This page tells how to sort a column by including first row. +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to sort a column by including first row? + +This following code samples demonstrate how to sort a column by including first row using C# (Cross-platform and Windows-specific) and VB.NET. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + #region Workbook initialization + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); + IWorksheet worksheet = workbook.Worksheets[0]; + #endregion + + #region Sort On Cell Values + //Creates the data sorter + IDataSort sorter = workbook.CreateDataSorter(); + + //This includes the first column for sorting range + sorter.HasHeader = false; + + //Range to sort + sorter.SortRange = worksheet.Range["D1:D26"]; + + //Adds a sort field: then by values in column D in descending order + ISortField sortField = sorter.SortFields.Add(3, SortOn.Values, OrderBy.Descending); + + //Setting the algorithm to sort the values + sorter.Algorithm = SortingAlgorithms.QuickSort; + sorter.Sort(); + #endregion + + #region Save + //Saving the workbook + workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx")); + #endregion + +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + #region Workbook initialization + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx"); + IWorksheet worksheet = workbook.Worksheets[0]; + #endregion + + #region Sort On Cell Values + //Creates the data sorter + IDataSort sorter = workbook.CreateDataSorter(); + + //This includes the first column for sorting range + sorter.HasHeader = false; + + //Range to sort + sorter.SortRange = worksheet.Range["D1:D26"]; + + //Adds a sort field: then by values in column D in descending order + ISortField sortField = sorter.SortFields.Add(3, SortOn.Values, OrderBy.Descending); + + //Setting the algorithm to sort the values + sorter.Algorithm = SortingAlgorithms.QuickSort; + sorter.Sort(); + #endregion + + #region Save + //Saving the workbook + workbook.SaveAs("Output.xlsx"); + #endregion +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx") + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + 'Creates the data sorter + Dim sorter As IDataSort = workbook.CreateDataSorter() + + 'This includes the first column for sorting range + sorter.HasHeader = False + + 'Range to sort + sorter.SortRange = worksheet.Range("D1:D26") + + 'Adds a sort field: then by values in column D in descending order + Dim sortField As ISortField = sorter.SortFields.Add(3, SortOn.Values, OrderBy.Descending) + + 'Setting the algorithm to sort the values + sorter.Algorithm = SortingAlgorithms.QuickSort + sorter.Sort() + 'Saving the workbook + workbook.SaveAs("Output.xlsx") +End Using +{% endhighlight %} +{% endtabs %} + +A complete working example in C# is present on this GitHub page. \ No newline at end of file From c167db8a3b67d1a59a7b7b6d1e85d9a2108c2dc8 Mon Sep 17 00:00:00 2001 From: VinothSF5015 Date: Tue, 14 Apr 2026 10:29:24 +0530 Subject: [PATCH 2/2] Update how-to-sort-a-column-by-including-first-row.md --- .../NET/faqs/how-to-sort-a-column-by-including-first-row.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-sort-a-column-by-including-first-row.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-sort-a-column-by-including-first-row.md index 07bd5c5fb..b0db49c1a 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-sort-a-column-by-including-first-row.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-sort-a-column-by-including-first-row.md @@ -1,6 +1,6 @@ --- title: Soritng using Syncfusion XLsIO | Syncfusion -description: This page tells how to sort a column by including first row. +description: This page tells how to sort a column by including first row using XLsIO in C# (Cross-platform and Windows-specific) and VB.NET. platform: document-processing control: XlsIO documentation: UG @@ -110,4 +110,4 @@ End Using {% endhighlight %} {% endtabs %} -A complete working example in C# is present on this GitHub page. \ No newline at end of file +A complete working example in C# is present on this GitHub page.