Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort Excel sheet by column using EPPlus

Tags:

excel

epplus

I'm using EPPlus to generate Excel workbooks.

I'm trying to figure out how to either:

  1. Sort a worksheet by a specific column (the equivalent of clicking sort A-Z in Excel) or...
  2. Set the sort order for a specific column's AutoFilter
like image 872
Ted Nyberg Avatar asked Nov 25 '22 09:11

Ted Nyberg


1 Answers

var startRow = 1;    
var startColumn= 1;
var endRow= 10;
var endColumn= 10;
var sortColumn = 5; //6th Column because index is ZeroBased.
using (ExcelRange excelRange = yourWorkSheet.Cells[startRow, startColumn, endRow, endColumn])
     {
         excelRange.Sort(sortColumn, true);
     }
like image 156
ajaysinghdav10d Avatar answered Nov 26 '22 23:11

ajaysinghdav10d